- 论坛徽章:
- 0
|
php中{}是什么意思
- <?php
- // Let's show all errors
- error_reporting(E_ALL);
- $great = 'fantastic';
- // 不行,输出为:This is { fantastic}
- echo "This is { $great}";
- // 可以,输出为:This is fantastic
- echo "This is {$great}";
- echo "This is ${great}";
- // Works
- echo "This square is {$square->;width}00 centimeters broad.";
- // Works
- echo "This works: {$arr[4][3]}";
- // This is wrong for the same reason as $foo[bar] is wrong
- // outside a string. In otherwords, it will still work but
- // because PHP first looks for a constant named foo, it will
- // throw an error of level E_NOTICE (undefined constant).
- echo "This is wrong: {$arr[foo][3]}";
- // Works. When using multi-dimensional arrays, always use
- // braces around arrays when inside of strings
- echo "This works: {$arr['foo'][3]}";
- // Works.
- echo "This works: " . $arr['foo'][3];
- echo "You can even write {$obj->;values[3]->;name}";
- echo "This is the value of the var named $name: {${$name}}";
- ?>;
复制代码 |
|