Connecting Tech Pros Worldwide Help | Site Map

how to get lowest value

  #1  
Old October 18th, 2006, 02:05 AM
jayipee@gmail.com
Guest
 
Posts: n/a
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.

  #2  
Old October 18th, 2006, 02:25 AM
Rik
Guest
 
Posts: n/a

re: how to get lowest value


jayipee@gmail.com wrote:
Quote:
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));

Grtz,
--
Rik Wasmus


  #3  
Old October 18th, 2006, 02:45 AM
Geoff Muldoon
Guest
 
Posts: n/a

re: how to get lowest value


luiheidsgoeroe@hotmail.com says...
Quote:
jayipee@gmail.com wrote:
Quote:
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);

Geoff M
  #4  
Old October 18th, 2006, 03:05 AM
Rik
Guest
 
Posts: n/a

re: how to get lowest value


Geoff Muldoon wrote:
Quote:
luiheidsgoeroe@hotmail.com says...
Quote:
>jayipee@gmail.com wrote:
Quote:
>>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


  #5  
Old October 18th, 2006, 08:55 AM
Geoff Berrow
Guest
 
Posts: n/a

re: how to get lowest value


Message-ID: <82c52$45358556$8259c69c$21674@news2.tudelft.nlfro m Rik
contained the following:
Quote:
Quote:
>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));
Sounds like a homework question.

Homeworky answer:

$array = array('log0'=>233,'log1' =354,'log2' =232,'log3' =255);
$count=1;
foreach($array as $key=>$value){
if($count==1 ){
$low_val =$value;
$low_key=$key;
}
elseif($value<$low_val){
$low_val =$value;
$low_key=$key;
}
$count++;
}
echo "$low_key =$low_val";

How to handle null values and duplicates left as an exercise. :-)
--
Regards,

Geoff Berrow
  #6  
Old October 18th, 2006, 10:55 AM
Kimmo Laine
Guest
 
Posts: n/a

re: how to get lowest value


<jayipee@gmail.comwrote in message
news:1161134572.618837.75610@m7g2000cwm.googlegrou ps.com...
Quote:
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

$array = array('log1' =354,'log2' =232,'log3' =155);
$test1 = array_search(min($array), $array);
$test2 = array_keys($array, min($array));

The difference between aray_search and array_keys is that _keys returns an
array of keys for matching elements. That means if several minimum values
are found, all matching elements are returned. Array_search just returns the
first.

--
"Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
http://outolempi.net/ahdistus/ - Satunnaisesti päivittyvä nettisarjis
spam@outolempi.net | rot13(xvzzb@bhgbyrzcv.arg)


Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to get the Smallest value from a list of values and how to do it with c# Sheena777 answers 5 October 23rd, 2008 06:59 PM
Finding lowest value in dictionary of objects, how? davenet answers 5 November 19th, 2007 05:05 PM
Find the lowest value in an array =?Utf-8?B?VGhvbWFzVDIy?= answers 30 September 12th, 2007 10:25 PM
dropping lowest value after an ascending sort sonic answers 2 February 6th, 2007 04:18 PM