0

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???

1
  • Thanks all - I had tested it on a previous array and it turns our "RESULT" was in one of the value keys... I changed the array and confused myself... Commented Jul 21, 2011 at 5:16

2 Answers 2

3

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

Sign up to request clarification or add additional context in comments.

Comments

2

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.