diff --git a/reference/var/functions/empty.xml b/reference/var/functions/empty.xml index 9ccb94a96579..b0530de44bc7 100644 --- a/reference/var/functions/empty.xml +++ b/reference/var/functions/empty.xml @@ -29,6 +29,7 @@ No warning is generated if the variable does not exist. That means empty is essentially the concise equivalent to !isset($var) || $var == false. + This also works for multidimensional arrays, you can reference deeply nested structures without raising warnings. @@ -79,7 +80,6 @@ $expected_array_got_string = 'somestring'; var_dump(empty($expected_array_got_string['some_key'])); var_dump(empty($expected_array_got_string[0])); var_dump(empty($expected_array_got_string['0'])); -var_dump(empty($expected_array_got_string[0.5])); var_dump(empty($expected_array_got_string['0.5'])); var_dump(empty($expected_array_got_string['0 Mostel'])); ?> @@ -91,9 +91,41 @@ var_dump(empty($expected_array_got_string['0 Mostel'])); bool(true) bool(false) bool(false) -bool(false) bool(true) bool(true) +]]> + + + + <function>empty</function> on multidimensional arrays + + [ + 'deep' => [ + 'nested' => 'value' + ] + ] +]; + +// we can use `empty()` with multidimensional arrays +if (!empty($multidimensional['some']['some']['nested'])) { + $someVariable = $multidimensional['some']['deep']['nested']; +} + +var_dump(empty($multidimensional['some-undefined-key'])); +var_dump(empty($multidimensional['some']['deep']['unknown'])); +var_dump(empty($multidimensional['some']['deep']['nested'])); +?> +]]> + + &example.outputs; + +