12

I have a JSONArray as shown below

{
    "output": [
        "a",
        "b",
        "c",
        "d",
        "e"
    ]
}

I need to find if "e" exists in the above array in php. Can someone help me out with this ?

6
  • what's with the downvotes? this is a perfectly fine question from a beginner Commented Nov 16, 2012 at 7:30
  • 1
    I'm guessing it's because the asker has shown none of their own efforts in trying to solve the issue, it comes across a little like: Hey do this for me cheers bye. Commented Nov 16, 2012 at 7:46
  • well I need to know what to search inorder to find my answer. I managed to do it the C++ way of traversing through each element and finding out the value and comparing it. Just thought this would help me understand some functions in php. Commented Nov 16, 2012 at 7:57
  • @lalith Tip: Always do a simple search in the manual: php.net/manual-lookup.php?pattern=find+in+array, 90% of the time that answers your question. Commented Nov 16, 2012 at 8:21
  • @deceze thank you, I just found that out. I am new to PHP I dint know it had such a good manual. thank a lot guys. Commented Nov 19, 2012 at 9:06

1 Answer 1

16
$array = json_decode($json, true);
if (in_array('e', $array['output'])) {
    ...
}
Sign up to request clarification or add additional context in comments.

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.