determining the key of an array
Posted: Thu Oct 27, 2005 3:18 pm
I have a $_POST value, that will be an element in an array.
Like this example:
How can I select the key from the array, where the value is Bob (the $name variable)?
Edit:
After thinking about it, I could do
but that seems a bit backwards. is there any other way to do it?
Like this example:
Code: Select all
$name = $_POST['name']; // we'll say the name is Bob
$namesa = mysql_query("SELECT names FROM table WHERE foo = '$bar'");
$names = $namesa['names'];
$array = explode(";",$names); // now I have Array ([0] => Jimmy, [1] => Bob, [2] => Steve)Edit:
After thinking about it, I could do
Code: Select all
$new = array_flip($array);
$key = $array[$name];