# A newbie question on array

#### Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

•  Subject
• Author
• Posted on

Hi,

I have a list of variables, for instance
\$var1= '12';
\$var2= '16';
\$var3= '15';

I want to know what is the max and which the name of the corresponding
variable. In other words that the max value is 16 and the varible is
\$var2 .

I suppose that i should use an array but which kind?

## Re: A newbie question on array

ver_for@yahoo.it (Marco) wrote in

Really? Why is the _string_ consisting of the letters
one and six the "maximum"?

--
Dave Patton
http://www.confluence.org /
My website: http://members.shaw.ca/davepatton /

## Re: A newbie question on array

.oO(Dave Patton)

In alphabetically order it is, but the OP probably wants to use numeric
values.

Micha

## Re: A newbie question on array

.oO(Marco)

Use an array and don't quote numeric values:

\$var = array(12, 16, 15);

Sort the array in reverse order:

arsort(\$var);
reset(\$var); // probably not necessary

Then look at the first element, there are different ways to do that:

key(\$var); // returns the key of the current element
current(\$var); // returns the value of the current element
each(\$var); // returns both key and value of the current element

HTH
Micha