php - Array search dont know search -
php - Array search dont know search -
i have array:
include("config.php"); $start = "2014-06-20 08:00:00"; $data = mysql_query ("select * evenement start = '$start'"); $zaznam = mysql_fetch_array ($data); while($zaznam = mysql_fetch_array ($data)) { $arr2[] = $zaznam["resourceid"]; //store query values in sec array }
if echo $arr2 this:
array ( [0] => stk1 )
now create status array_search:
if (array_search('stk1', $arr2)) { echo "arr2 contains stk1 <br>"; } else { echo "arr2 not contains stk1 <br>"; }
but arr2 not contains stk1 how possible? im doing wrong?
that totally right behaviour php.
the documention homecoming value says:
returns key needle if found in array, false otherwise.
in case getting 0 evaluates false in if.
you have check if value not false using !==
operator.
if (array_search('stk1', $arr2) !== false) { echo "arr2 contains stk1 <br>"; } else { echo "arr2 not contains stk1 <br>"; }
php arrays condition
Comments
Post a Comment