How can I add arrays into an existing array item?
For instance:
$user[$user->id] = array(//values);
But if that user needs another array added, I want all data to fall under that user ID in the array.
I want to store orders a user has made, so I can look up all orders on 开发者_StackOverflow社区the fly by user ID in the $user array above.
$user[$user->id]['orders'] = array();
Or
$user[$user->id] = array(
'orders' => array(
array(// data for order #1),
array(// data for order #2),
array(// data for order #3)
);
);
// Looping over the orders
foreach($user[$user->id]['orders'] as $order) {
// Do something with the order
}
Have you tried something like:
$user[$id] = array_merge($user[$id], array(//values));
Give the orders a key
$user[$user->id] = array(
"orders" => array(values)
);
精彩评论