PDA

View Full Version : finding key instead of value


foxfirediego
11-05-2007, 07:52 PM
Ok I have the following array:

$names = array("Venore", "Folda", "Dame");
And I can print like this:
$names[0]; -> return Venore
$names[1]; -> return Folda
$names[2]; -> return Dame

but, what if I want to use:
$names[Venore]; -> return 0
$names[Folda]; -> return 1
$names[Dame]; -> return 2

thanks

Adrian Schneider
11-05-2007, 07:54 PM
Look into array_search()

Another option (I find it faster if you do it often) is creating a duplicate array that is flipped with array_flip(), then you can just use $array['Venore'] to get your 0 value.

foxfirediego
11-06-2007, 10:52 AM
Thank you very much SirAdrian, I'll give a try!