I have an array like this:
[1] => Array
(
[id] => 7
[ticket_id] => 12
[client_id] => 174
[thread_name] =>
[added_by] => 2
[created_at] => 2015-07-28 23:24:07
[updated_at] => 2015-07-28 23:24:07
[notes] => Array
(
[0] => Array
(
[id] => 21
[user_id] => 2
[notes] => Not all those who wander are lost!
[notes_attachment] =>
[deleted_at] =>
[created_at] => 2015-07-28 23:34:31
[updated_at] => 2015-07-28 23:34:31
[thread_id] => 7
[users] => Array
(
[0] => Array
(
[user_id] => 1
)
[1] => Array
(
[user_id] => 2
)
)
)
)
)
And I need to manipulate the users array in the notes array to something like this.
[users] => Array
(
[0] => 1
[1] => 2
)
So, basically, I need an array for ids in the users array.
I tried doing it, but it takes three loop to get into users.
How can I do that more efficiently ??
NOTE: This is just one of the structure from multiple arrays. Like, I have 4 threads and multiple notes in each of them.
Also, I need to manipulate the existing array and not just take the data from it.
My attempt:
$tmp = array();
foreach($data as $value) {
foreach($value['notes'] as $notes) {
if(!empty($notes['users'])){
foreach($notes['users'] as $users) {
$tmp[] = $users['user_id'];
unset($notes['users']);
$notes['users'] = $tmp;
}
}
}
}