php in_array() usage
I have an array of data and I am checking the result by using the in_array()开发者_运维技巧 function, yet for some reason it is returning false???
here is the code:
var_dump($result);
var_dump(in_array("RESULT", $result));
and here is the output:
array(4) {
["TIMESTAMP"]=>
string(29) "#Wed Jul 20 22:00:32 PDT 2011"
["CAUSE"]=>
string(34) "Username and Password do not match"
["RESULT"]=>
string(5) "FALSE"
[""]=>
NULL
}
bool(false)
I'm confused???
You are looking for a key not a value. You want to use this function:
http://php.net/manual/en/function.array-key-exists.php
in_array()
function checks the values in the array
in your case you could use
in_array("RESULT", array_keys($result));
or
array_key_exists("RESULT", $result);
or
isset($result["RESULT"]);
精彩评论