Reputation: 83
I've an associated array with 20 elements whose child array looks like
(int) 2 => array(
'Comment' => array(
'id' => '5',
'user_id' => '13',
'time' => '2012-05-18 14:47:36'
),
'User' => array(
'name' => 'User name'
)
)
Now I want to extract the field name from its child array User with cakephp's set utility and append it to the child array Comment. Is there a one way step to do this other than using a for or foreach loop?
(int) 2 => array(
'Comment' => array(
'id' => '5',
'user_id' => '13',
'time' => '2012-05-18 14:47:36',
'name =>'User name'
)
)
Upvotes: 0
Views: 285
Reputation: 18706
It doesn't answer your question, but doing this with a foreach
is a one way step too:
foreach ($arrays as $array)
$array['Comment']['name'] = $array['User']['name'];
I believe there's no need to use some utility, just for the sake of using an utility.
Especially that it'll do a foreach
itself.
Upvotes: 1