mercredi 22 juillet 2020

How to see if json array contains a value? [duplicate]

So, I'm new to php and while testing some services, I have a JSON object:

{
  "entry": [
    {
      "authorId": "@me",
      "type": "USER"
    },
    {
      "authorId": "514",
      "type": "USER"
    },
    {
      "authorId": "516",
      "type": "USER"
    }
  ],
  "count": 3,
  "totalResults": 3
}

and I need to assert that '@me' is part of this object. I tried something like:

$Obj->assertTrue(array_key_exists('@me', $response['entry']));

but it won't just work. Can someone give me a hint regarding this? Thank you

EDIT: '@me' can be anywhere in the array, not on the first position and I'm asking this for a a test in codecept, so I need to an assert directly

Aucun commentaire:

Enregistrer un commentaire