maybe (not tested)..
$foo = array( 0, 57.81, 73.906, 97.26, 0, 32.79, 77.81, 28.912, 0,
0, 0,
0, 0, 0, 27.12 );
arsort($foo);
$val = current($foo);
array_walk($foo, create_function('&$v, $k, $val', '$v = $v > 0 ?
$val : 0;'), $val);
ksort($foo);
On Aug 10, 5:11 pm, "Gonzalo Servat" <[EMAIL PROTECTED]> wrote:
> On 8/10/07, Unite <[EMAIL PROTECTED]> wrote:
>
>
>
> > I know this isnt really a CakePHP problem but I need help in my logic
> > mathematically and since most of you reading this are Maths geniuses
> > heres the question.
>
> > I have a array and want to make each set have the highest value in the
> > set. (sets are seperated by 0's)
>
> [..snip..]
>
> Is this what you want?
>
> <?php
>
> $foo = array( 0, 57.81, 73.906, 97.26, 0, 32.79, 77.81, 28.912, 0, 0, 0,
> 0, 0, 0, 27.12 );
>
> $toCompare = array();
> foreach( $foo as $i => $val )
> {
> if( $val == 0 )
> {
> if( $toCompare )
> {
> sort( $toCompare );
> $max = $toCompare[count($toCompare) - 1];
> foreach( $toCompare as $k => &$v )
> {
> $v = $max;
> }
> $toCompare = array();
> }
> }
> else
> {
> array_push( $toCompare, &$foo[$i] );
> }
>
> }
>
> print_r( $foo );
>
> ?>
>
> There are probably better (and shorter?) ways of doing it, but that's the
> rush job I came up with.
>
> Hope this helps.
>
> - Gonzalo
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---