Array search - Part 2
Posted: Wed Aug 17, 2005 8:26 am
Hi,
I have found some odd behavious with the array_serach fnction.
Look at this piece of code:
Output is as to be expected:
-1--2--3-
ie. the file is 3 lins long with the number 1,2,3 on each line. I am then searching the array for a match as follows:
Now the strange behaviour I have noticed is that array_search does not seem to look in or compare index 0 of the array. I have tested this, and which ever value is in index 0 - does not evalute to true when call the function.
Am I going mad?
Rob.
I have found some odd behavious with the array_serach fnction.
Look at this piece of code:
Code: Select all
$list=file("email_list.txt");
$list=array_map("trim",$list);
foreach($list as $val){
echo "-$val-";
}-1--2--3-
ie. the file is 3 lins long with the number 1,2,3 on each line. I am then searching the array for a match as follows:
Code: Select all
if (array_search('1', $list)) {
echo"Value exists in the array!";
}Am I going mad?
Rob.