@@ -862,12 +862,11 @@ error_reporting(E_ALL);
862862
863863$arr = array('fruit' => 'apple', 'veggie' => 'carrot');
864864
865- // Correct
865+ // 正确
866866echo $arr['fruit'], PHP_EOL; // apple
867867echo $arr['veggie'], PHP_EOL; // carrot
868868
869- // Incorrect. This does not work and throws a PHP Error because
870- // of an undefined constant named fruit
869+ // 不正确。此操作无效,并会因未定义名为 fruit 的常量而抛出 PHP 错误
871870//
872871// Error: Undefined constant "fruit"
873872try {
@@ -876,24 +875,21 @@ try {
876875 echo get_class($e), ': ', $e->getMessage(), PHP_EOL;
877876}
878877
879- // This defines a constant to demonstrate what's going on. The value 'veggie'
880- // is assigned to a constant named fruit.
878+ // 此处定义了一个常量以说明其行为,将值 'veggie' 赋予名为 fruit 的常量
881879define('fruit', 'veggie');
882880
883- // Notice the difference now
881+ // 注意现在不同
884882echo $arr['fruit'], PHP_EOL; // apple
885883echo $arr[fruit], PHP_EOL; // carrot
886884
887- // The following is okay, as it's inside a string. Constants are not looked for
888- // within strings, so no error occurs here
885+ // 以下写法是允许的,因为其位于字符串内部。常量在字符串中不会被查找,因此此处不会产生错误
889886echo "Hello $arr[fruit]", PHP_EOL; // Hello apple
890887
891- // With one exception: braces surrounding arrays within strings allows constants
892- // to be interpreted
888+ // 例外:字符串中用花括号包围的数组允许对常量进行解析
893889echo "Hello {$arr[fruit]}", PHP_EOL; // Hello carrot
894890echo "Hello {$arr['fruit']}", PHP_EOL; // Hello apple
895891
896- // Concatenation is another option
892+ // 拼接是另一种选择
897893echo "Hello " . $arr['fruit'], PHP_EOL; // Hello apple
898894?>
899895]]>
@@ -1092,8 +1088,8 @@ array(3) {
10921088 <title >比较</title >
10931089
10941090 <para >
1095- 可以用 <function >array_diff</function > 函数和
1096- < link linkend =" language.operators.array" >数组运算符</link > 来比较数组。
1091+ 可以用 <function >array_diff</function > 函数和< link
1092+ linkend =" language.operators.array" >数组运算符</link >来比较数组。
10971093 </para >
10981094 </sect2 >
10991095
@@ -1204,7 +1200,7 @@ $arr6 = [...$arr4, ...$arr5]; // works. [1, 2, 3, 4, 5]
12041200 <programlisting role =" php" >
12051201<![CDATA[
12061202<?php
1207- // This:
1203+ // 这里:
12081204$a = array( 'color' => 'red',
12091205 'taste' => 'sweet',
12101206 'shape' => 'round',
0 commit comments