Checking for existing key in multi-dimensional array Say I have a data structure like this:

array(3) {
  ["id"]=&gt;
  int(1)
  ["name"]=&gt;
  string(3) "foo"
  ["message"]=&gt;
  array(1) {
    ["action"]=&gt;
    string(3) "PUT"
  }
}


Where 'message' and 'action' are both optional.  To check if they're present my first attempt would be to write something like this:

if (array_key_exists('message', $array) &amp;&amp; array_key_exists('action', $array['message'])){
}


Is there a cleaner implementation?
You can just do this!

if (isset($array["message"]["action"])) { /*...*/ }


Proof:

&lt;?php

error_reporting(E_ALL);
ini_set('error_reporting', E_ALL);
ini_set('display_errors', 1);

$array = [
    "id" =&gt; 1,
    "name" =&gt; "foo",
    "message" =&gt; [
        "action" =&gt; "PUT",
    ],
];

var_dump(isset($array["message"]["action"])); // true


$array = [
    "id" =&gt; 1,
    "name" =&gt; "foo"
];

var_dump(isset($array["message"]["action"])); // false


No log entries.

Do note that if your value is null, then isset will also return false. You probably shouldn't be creating values with null.