Skip to content

Commit

Permalink
remove deprecated example, add multidimensional arrays examples
Browse files Browse the repository at this point in the history
  • Loading branch information
ludrob committed Jan 14, 2025
1 parent 9b26644 commit da98656
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions reference/var/functions/empty.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
No warning is generated if the variable does not exist.
That means <function>empty</function> is essentially the
concise equivalent to <command>!isset($var) || $var == false</command>.
This also works for multidimensional arrays, you can reference deeply nested structures without raising warnings.
</para>
</listitem>
</varlistentry>
Expand Down Expand Up @@ -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']));
?>
Expand All @@ -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)
]]>
</screen>
</example>
<example>
<title><function>empty</function> on multidimensional arrays</title>
<programlisting role="php">
<![CDATA[
<?php
$multidimensional = [
'some' => [
'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']));
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
bool(true)
bool(true)
bool(false)
]]>
</screen>
</example>
Expand Down

0 comments on commit da98656

Please sign in to comment.