且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PHP-如何从多维数组中回显值

更新时间:2023-02-23 10:01:01

以前,如果在该名称下未定义任何常量,则每个不带引号的字符串都被视为字符串,但是从 PHP 7.2 起,现在发出的错误级别为 E_WARNING 为什么$ foo [bar]错误?

Previously every string without quotes was treated like string if there was no Constant defined under this name, but from PHP 7.2 now issues error of level E_WARNING. Why is $foo[bar] wrong?

PHP Warning:  Use of undefined constant test - assumed 'test' (this will throw an Error in a future version of PHP)

在此示例中,列表被视为构造 list()

In this example list is treated as construct list(). Using bare strings in associative arrays as keys is deprecated and should be avoided.

正确的方法是使用引号(单引号或双引号)来调用它:

Correct way is to call it with quotes (single or double):

echo $request['SUCCESS'][0]['LIST'];
echo $request['SUCCESS'][0]['LIST']['credit'];