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 cake-php@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to