How can I concatenate arrays in PHP5 without repeating the name?
This is what I tried to do, but it doesn't work:
$thisProduct = $data['deliveryMethod'][1209];
$thisProductReceiver = $thisProduct['receiver'];
And after I do:
$lastName = $thisProductReceiver['lastName'];
I get this error:
Illegal string offset 'receiver'
The Problem is you are mixing arrays with normal variables.
See here, the first line
$thisProduct = $data['deliveryMethod'][1209];
$thisProduct
is a normal variable, (not an array). You are storing the value from an array $data
to this $thisProduct
variable.
Now see the second line $thisProductReceiver = thisProduct['receiver'];
You are assigning thisProduct['receiver']
to $thisProductReceiver
variable. The Problem here was we already know that $thisProduct
is an array but you are accessing it as an array thisProduct['receiver'];
[Which is the source of the error]