0

I have decoded a JSON message using a PHP script. I would like to check if one of the parameters (which is a blank array i.e. array()) is blank but I cannot find the value to check it against in an if statement.

To clarify what I am referring to, here is an example in JSON format:

"contexts": [],
"metadata": {
  "intentId": "8c7c5399-7eba-41ea-bda7-42075813a922",
  "webhookUsed": "true",
  "webhookForSlotFillingUsed": "false",
  "isFallbackIntent": "false",
  "intentName": "broom1.off.time"
}

It is the "contexts": [] value I would like to check against. In my PHP script I have the following code to do so:

if ($update["contexts"] == array()) {
    // do_something_here
}

N.B. $update has used the json_decode method to get the values of the JSON file. My question is, what is the value of that contexts paramenter?

Thanks.

7
  • 1
    php.net/manual/en/function.empty.php or php.net/manual/en/function.is-array.php and empty. Commented Jul 19, 2018 at 15:29
  • The value is empty. There is nothing. I don't understand the question Commented Jul 19, 2018 at 15:31
  • But what you have should work 3v4l.org/Q0Fk6 maybe better with === Commented Jul 19, 2018 at 15:32
  • What are you currently getting as the result? What makes you think that it is not working? Commented Jul 19, 2018 at 15:35
  • use json_decode(URL,true) and then check if empty($update['contexts') is true Commented Jul 19, 2018 at 15:36

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.