Jump to content

[SOLVED] max function and array


ted_chou12

Recommended Posts

<?php
$arrays = array('05' => 'Ted',
                    '02' => 'A',
                      '04' => 'B',);

foreach ($arrays as $number => $name)
echo(max($arrays));
?>
the above code does not work but give you an idea, what i want is the name with the most number...
thanks
if you dont understand please just reply to this
Ted
Link to comment
https://forums.phpfreaks.com/topic/31843-solved-max-function-and-array/
Share on other sites

but aren't you asking the same question? Using the same data from the same table? Only difference I'm seeing is that you are asking how to do it with php instead of sql.  Does that about sum it up?  Because if so, then stick with the sql version; that's what it was designed for.
[code=php:0]<?php
$arrays = array('05' => 'Ted',
                    '02' => 'A',
                      '04' => 'B',);
$max = '0'; # Must be less than all numbers
foreach ($arrays as $number => $name) {
  $max = max($max, $number);
}
echo "Maximum is number $max with value {$arrays[$max]}\n";
?>[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.