From fe4d5f0621875732b2b83eb8648bdbf1e9e49732 Mon Sep 17 00:00:00 2001 From: Sander Roobol Date: Tue, 7 May 2002 09:57:26 +0000 Subject: [PATCH] Clearify the array-do's-and-don'ts - thanks to Hugh W Prior (#17065) git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@81397 c90b9560-bf6c-de11-be94-00142212c4b1 --- language/types.xml | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/language/types.xml b/language/types.xml index 9ea4cb9c1e..36a40ba712 100644 --- a/language/types.xml +++ b/language/types.xml @@ -1,5 +1,5 @@ - + Types @@ -1204,7 +1204,9 @@ unset( $a[2] ); Why is <literal>$foo[bar]</literal> wrong? - You might have seen the following syntax in old scripts: + You should always use quotes around an associative array index. + For example, use $foo['bar'] and not $foo[bar]. But why is $foo[bar] + wrong? You might have seen the following syntax in old scripts: - This is wrong, but it works. Then, why is it wrong? The reason is - that, as stated in the + + As stated in the syntax section, there must be an expression between the square brackets ('[' and ']'). That means that you can write things like this: