Re: Question about array_search

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> Say I'm trying to add a value to an array, only if it's not already in
> there somewhere; so I do an array_search to see. The problem is that if
> the item is at index 0 in the array, array_search gives the same answer
> as if it's not in there at all. How does one circumvent this potential
> pitfall?

I think this would work (I could be wrong)

$array = array(0 => 'blue', 1 => 'red', 2 => 'green', 3 => 'red');

if(($key = array_search('bluesf', $array)) !== FALSE) {
	echo $key;
}

if(($key = array_search('blue', $array)) !== FALSE) {
	echo $key;
}

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux