|
Posted by Rik on 10/18/06 02:22
Geoff Muldoon wrote:
> luiheidsgoeroe@hotmail.com says...
>> jayipee@gmail.com wrote:
>>> hi to all. can anybody help me figuring out how to get the minimum
>>> value from this list.
>>>
>>> log1 354
>>> log2 232
>>> log3 155
>>>
>>> from the above list i want to have a return value "log3" since this
>>> is the lowest value in the list.
>>>
>>> I tried to use $test = min(array('log1' => 354,'log2' => 232,'log3'
>>> => 155));
>>> but it returns only the value 155 and not log3
>>>
>>> i would be very glad if someone can help me.
>>
>> $array = array('log1' => 354,'log2' => 232,'log3' => 155);
>> asort($array);
>> $min_key = reset(array_keys($array));
>
> or:
>
> $log_array = array("log1"=>354, "log3"=>155, "log2"=>232);
> arsort($log_array);
> $log_array = array_flip($log_array);
> echo array_pop($log_array);
In most cases, yes.
Now try:
$log_array = array("log1"=>354, "log3"=>null, "log2"=>232);
You can see why I'm a bit reluctant to use values as the keys.
Grtz,
--
Rik Wasmus
Navigation:
[Reply to this message]
|