Forum Moderators: coopster

Message Too Old, No Replies

array_search is not working properly

seems to not always find a string which already exists in array

         

willis1480

5:42 pm on Nov 9, 2004 (gmt 0)

10+ Year Member



here is my code:
----------------------------------------
$key=array_search($row{0},$array_name);
if(!$key){
array_push($array_name,$row{0});
}
----------------------------------------
This should only put entries in the array that dont already exist, but it is not working. Any ideas on why?

willis1480

5:47 pm on Nov 9, 2004 (gmt 0)

10+ Year Member



well came across the solution, sorry for posting.

This code works:

$key=array_search($row2{0},$array_name);
if($key===false){
array_push($array_name,$row2{0});
}

This code does not work:
$key=array_search($row2{0},$array_name);
if($key==false){
array_push($array_name,$row2{0});
}

NOTE: It is the double equals vs. tripple equals which is why the!$key did not work as well. Rookie error :)