473,385 Members | 1,486 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

how to get lowest value

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.

Oct 18 '06 #1
5 1937
Rik
ja*****@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));

Grtz,
--
Rik Wasmus
Oct 18 '06 #2
lu************@hotmail.com says...
ja*****@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);

Geoff M
Oct 18 '06 #3
Rik
Geoff Muldoon wrote:
lu************@hotmail.com says...
>ja*****@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
Oct 18 '06 #4
Message-ID: <82***************************@news2.tudelft.nlfro m Rik
contained the following:
>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
Oct 18 '06 #5
<ja*****@gmail.comwrote in message
news:11*********************@m7g2000cwm.googlegrou ps.com...
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
sp**@outolempi.net | rot13(xv***@bhgbyrzcv.arg)
Oct 18 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: George Dainis | last post by:
How do I code a SQL SELECT statement so that always only this record is retrieved which matches a certain criteria AND has the lowest ID (= value in key field aaa)? It must me something like ...
8
by: starman7 | last post by:
i have a table with objects in categories and their positions. there will be several rows with category 400, and they will have various positions, i want to delete only the row with the lowest...
17
by: rhitz1218 | last post by:
Hi, I'm trying to create a function that will sort a number's digits from highest to lowest. For example 1000 - will become 0001 or 1234 to 4321
4
by: tomek milewski | last post by:
Hello, I have a map with keys that can be compared each other. I need a method that returns the lowest and the greatest key from that map. Now I'm using begin() and rbegin() which gives...
54
namcintosh
by: namcintosh | last post by:
First of all, here is my program: #include <iostream> #include <conio> using namespace std; //Function prototype void getscore(int&, int&, int&, int&, int&); void findLowest (int, int,...
30
by: =?Utf-8?B?VGhvbWFzVDIy?= | last post by:
Hello, I have an array that holds 4 values ( they contain random numbers). I would like to find the lowest value (if there is a tie i would like to find one of the tie.) then remove that value....
5
by: davenet | last post by:
Hi, I'm new to Python and working on a school assignment. I have setup a dictionary where the keys point to an object. Each object has two member variables. I need to find the smallest value...
6
by: Patrick Fisher | last post by:
Hi I have tables from 12 suppliers each of whom can supply the same part, I need to be able to create a table or query containing a list of suppliers who can supply at the lowest price for each...
18
by: JC2710 | last post by:
I have a query that picks the lowest total by using a Group By clause. But if there are two lowest totals of the same amount I only want my query to return one value. Any ideas? Thanks
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.