cvs: /phpdoc/language types.sgml
| From: | Torben Wilson | Date: | Mon, 15 Nov 1999 00:50:49 +0000 |
| Subject: | cvs: /phpdoc/language types.sgml | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-12543@lists.php.net to get a copy of this message | ||
cslawi Sun Nov 14 19:50:49 1999 EDT
Modified files:
/phpdoc/language types.sgml
Log:
Note PHP4's syntax for putting multidim arrays in strings.
Index: phpdoc/language/types.sgml
diff -u phpdoc/language/types.sgml:1.6 phpdoc/language/types.sgml:1.7
--- phpdoc/language/types.sgml:1.6 Sun Nov 14 18:43:00 1999
+++ phpdoc/language/types.sgml Sun Nov 14 19:50:48 1999
@@ -234,31 +234,43 @@
</programlisting>
</informalexample></para>
- <note>
- <para>
- It is not possible to reference multidimensional arrays directly
- within strings. For instance, the following will not have the
- desired result:
- <informalexample>
- <programlisting role="php">
+ <para>
+ In PHP3 it is not possible to reference multidimensional arrays
+ directly within strings. For instance, the following will not
+ have the desired result:
+ <informalexample>
+ <programlisting role="php">
$a[3]['bar'] = 'Bob';
echo "This won't work: $a[3][bar]";
- </programlisting>
- </informalexample>
+ </programlisting>
+ </informalexample>
- In PHP3, the above will output
- <computeroutput>This won't work: Array[bar]</computeroutput>. The string
- concatenation operator, however, can be used to overcome this:
-
- <informalexample>
- <programlisting role="php">
+ In PHP3, the above will output
+ <computeroutput>This won't work: Array[bar]</computeroutput>. The string
+ concatenation operator, however, can be used to overcome this:
+
+ <informalexample>
+ <programlisting role="php">
$a[3]['bar'] = 'Bob';
echo "This will work: " . $a[3][bar];
- </programlisting>
- </informalexample>
+ </programlisting>
+ </informalexample>
- </para>
- </note>
+ </para>
+
+ <para>
+ In PHP4, however, the whole problem may be circumvented by
+ enclosing the array reference (inside the string) in curly
+ braces:
+ <informalexample>
+ <programlisting role="php">
+$a[3]['bar'] = 'Bob';
+echo "This will work: {$a[3][bar]}";
+ </programlisting>
+ </informalexample>
+
+ </para>
+
<para>
You can "fill up" multi-dimensional arrays in many ways,