So I have an Array set up as follows
Array
(
[0] => App\Model\Entity\Member Object
(
[id] => 20
[fname] => John
// ...
[member_attribute] => Cake\ORM\Entity Object
(
[id] => 13
[membership_status] => Active
[last_payment] => 1541581496
// ...
)
)
I'm using a foreach loop for the first level
foreach ($aArray as $Member => $Value)
However I can't access the [member_attributes]
data because it's in its own array.
Any help?
The items in your array are objects, so use object notation to access them:
foreach ($aArray as $Member => $Value) {
$id = $Value->member_attribute->id;
}
There also is no need to use the key => value form of the foreach, you could just access your Members like:
foreach ($aArray as $Member) {
$id = $Member->member_attribute->id;
}
That may be a matter of preference, however, I think it is more clear.