我在ubuntu 16.04上使用Laravel 5.3,当我运行此代码时:
echo "<pre>";
print_r($currentSessions[0]);
echo "</pre>";
echo "<pre>";
print_r($lmirOrder);
echo "</pre>";
返回:
$ currentSessions [0]是:
stdClass Object
(
[iID] => 484444768
[bStatus] => SESSION_ONHOLDBUTCUSTOMERLEFT
[sStatus] => Closed by waiting customer
[iEntry] => 404466296
[sEntry] => Technical Support
[iTechnician] => 17536581
[sTechnician] => Removed
[sStartTime] => 11/23/2016 2:48:35 PM
[iWaitingTimeInSec] => 2 Hours
[sCustomField0] => removed
[sCustomField1] => removed
[sCustomField2] => Array
(
[phoneNumber] => removed
[emailAddress] => removed
)
[sCustomField3] =>
[sCustomField4] =>
[sCustomField5] =>
[sLanguage] => en
[sTransferredTo] =>
[sTransferredComment] =>
[bIsLead] => 1
[bHandingOff] =>
)
$ lmirOrder是:
Array
(
[1] => sTechnician
[2] => sCustomField0
[3] => sCustomField2[phoneNumber]
[4] => sStatus
[5] => sStartTime
[6] => sCustomField1
[7] => iWaitingTimeInSec
[8] => sCustomField2[emailAddress]
)
当我回显时,为什么会出现“数组到字符串转换”错误:
echo $currentSessions[0]->$lmirOrder[4];
非常感谢任何帮助!
答案 0 :(得分:0)
这是因为声明$currentSessions[0]->$lmirOrder[4]
实际上被解释为{$currentSessions[0]->$lmirOrder}[4]
导致在对象上查找属性Array
。
<?php
$a = new stdClass();
$a->test = 'Hello World';
$a->Array = "You didn't want me";
$b = ['test'];
// Notice: Array to string conversion in php shell code on line 6
// string(1) "Y"
var_dump($a->$b[0]);
// string(11) "Hello World"
var_dump($a->{$b[0]});