Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove deprecated example, add multidimensional arrays examples #4394

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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