开发者

php in_array() usage

开发者 https://www.devze.com 2023-03-21 16:58 出处:网络
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???

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"]);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号