From da986565462c5ca494dcbd7a9f870883bac2023a Mon Sep 17 00:00:00 2001 From: ludrob Date: Tue, 14 Jan 2025 20:53:01 +0000 Subject: [PATCH 1/3] remove deprecated example, add multidimensional arrays examples --- reference/var/functions/empty.xml | 36 +++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/reference/var/functions/empty.xml b/reference/var/functions/empty.xml index 9ccb94a96579..966bcb4a4589 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; + + From cb36a6bd500f92ac11fe89cbde0b683aa21b12da Mon Sep 17 00:00:00 2001 From: ludrob Date: Wed, 15 Jan 2025 10:15:50 +0000 Subject: [PATCH 2/3] Update reference/var/functions/empty.xml --- reference/var/functions/empty.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reference/var/functions/empty.xml b/reference/var/functions/empty.xml index 966bcb4a4589..068518b2224a 100644 --- a/reference/var/functions/empty.xml +++ b/reference/var/functions/empty.xml @@ -109,7 +109,7 @@ $multidimensional = [ ] ]; -// we can use empty with multidimensional arrays +// we can use `empty()` with multidimensional arrays if (!empty($multidimensional['some']['some']['nested'])) { $someVariable = $multidimensional['some']['deep']['nested']; } From 3c9e990607b28a0a564e542bc9cbccb6b80b34d7 Mon Sep 17 00:00:00 2001 From: ludrob Date: Wed, 15 Jan 2025 10:34:42 +0000 Subject: [PATCH 3/3] improve formatting (indentation) Co-authored-by: Luffy <52o@qq52o.cn> --- reference/var/functions/empty.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reference/var/functions/empty.xml b/reference/var/functions/empty.xml index 068518b2224a..b0530de44bc7 100644 --- a/reference/var/functions/empty.xml +++ b/reference/var/functions/empty.xml @@ -99,7 +99,7 @@ bool(true) <function>empty</function> on multidimensional arrays - [