Not logged in

Your Account

Find Value in Array

Home/Tutorials/Find Value in Array

Find Value in Array

Content by: Steve Stewart

Posted a year ago with 721 views

Find Needle in Haystack

A term used for looking in arrays too see if value exists.
First we'll create an array.
Then the needle (Word) we want to find.
An we'll use php array_search.

$haystack = array('audi', 'bmw', 'ford', 'saab', 'vauxhaul');
$needle = 'saab';
$index = array_search($needle, $haystack);
if(!array_search($needle, $haystack)){
	echo 'We did not find '.$needle.'';
} else {
    echo $needle.' was found';