如何在PHP5中连接数组而不重复名称?
这就是我试图做的,但它不起作用:
$thisProduct = $data['deliveryMethod'][1209];
$thisProductReceiver = $thisProduct['receiver'];
在我这样做之后:
$lastName = $thisProductReceiver['lastName'];
我得到这个错误:
Illegal string offset 'receiver'
问题是将数组与普通变量混合。
看到这里,第一行
$thisProduct = $data['deliveryMethod'][1209];
$thisProduct
是一个普通变量(而不是数组)。您正在将数组$data
中的值存储到此$thisProduct
变量中。
现在看第二行$thisProductReceiver = thisProduct['receiver'];
您正在将thisProduct['receiver']
分配给$thisProductReceiver
变量。这里的问题是,我们已经知道$thisProduct
是一个数组,但您正在将其作为数组thisProduct['receiver'];
访问[这是错误的来源]