[PHP] Numeric Index of an array

2004-05-02 Thread Natascha Chrobok
How can I get the numeric Index of an array when the index is a string?

i.e

$myArray = array (first = my first value,
   second = my second value,
   third = my third value);
Lets say I want the Index of the my second one: this would be  second 
or numerid 1 (because the numeric index starts at zero).

How can I get the numeric index when I only have the string-index (so 
array_keys is a nono) without making a loop like:

$i = 0; 
foreach ($myArray as $index = $value)
{
if ($index == 'second')
{   
echo $i;
}
$i++;
}
Is there another way to get the numeric index?

thanx,

Natascha

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Numeric Index of an array

2004-05-02 Thread Marek Kilimajer
Natascha Chrobok wrote:
How can I get the numeric Index of an array when the index is a string?

string indexes don't have numeric indexes. they are in order however, if 
you want to find the order of a value, use:

echo array_search(array_search(my second value, $myArray), 
array_keys($myArray));

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php