PDA

View Full Version : Return Index with in_array


melissa820
02-04-2005, 07:53 PM
I was wondering if there is a function to do this. I want to find out if a certain string is in an array and if it is there, what index (key) is it at.
What I need is a way to get the index (1 in the example case below).
Basically it is just because I want to do an 'unset' on it (remove it from the array) if it is there.

Eg. :

$myArray = array( 0 => "Dog",
1 => "Cat",
2 => "Bird");
//the in_array function returns true here:
$isThere = in_array("Cat", $myArray);

raf
02-04-2005, 07:57 PM
http://www.php.net/manual/en/function.array-search.php

melissa820
02-04-2005, 08:00 PM
Duh! I knew there had to be something I just couldn't think of what it could be named.

Thanks!