Page 1 of 1

obtaining array key from a value

Posted: Wed Apr 14, 2004 5:43 am
by davidklonski
Hello

assuming I have the following array definition:

Code: Select all

<?php
$a = Array('a' => 'one',  'b' => 'two',  'c' => 'three',  'd' => 'four');
?>
I have a variable holding one of the array's values (for example, 'four'). Is there a php function which can give me the key that matches that value in the array? For example, in this case the key would be 'd'

thanks in advance

Posted: Wed Apr 14, 2004 5:57 am
by Wayne

Code: Select all

$the_key = array_search($your_variable, $a);