Lalith B
Lalith B

Reputation: 12239

Find if value exists in a JSONArray in php

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 ?

Upvotes: 12

Views: 12205

Answers (1)

deceze
deceze

Reputation: 522075

$array = json_decode($json, true);
if (in_array('e', $array['output'])) {
    ...
}

Upvotes: 16

Related Questions