为什么这个PHP数组直接访问不起作用


Why does this PHP Array direct access not work?

print_r($testarray(给出:

大堆([1] =>阵列([id]=>1[帐户]=>测试用户[sum]=>152[总和]=>0.08[平均值]=>10.133333333333[速度]=>14167.42684444)

)

echo"用户ID 1:$testarray[1][Speed]的速度";

只是给出:

PHP注意事项:数组到字符串的转换

我做错了什么?

echo"用户ID 1的速度:"$testarray[1][‘speed’];试试这个

echo $testarray[1]['speed']

不是

echo $testarray[1][speed]

不能简单地打印Array对象。

$testarray[1]是一个数组。

使用print_r()

或者您可以简单地从$testarray[1]中单独获得值:

$speed = $testarray[1]["speed"];

因为你没有封装或数组,也没有隔离你想要回显的内容,PHP可以理解你想要回隐的内容,它是回显$testarray[1],这是一个数组,然后是字面上的[speed]

echo "Speed for User ID 1: " . $testarray[1]['speed'];

echo "Speed for User ID 1: {$testarray[1]['speed']}";