I have two arrays, the second is multidimensional. I'm trying to return a third array where the service_id in Array2 match the values in Array1.
Array1
(
[0] => 158
[1] => 162
)
Array2
(
[localhost] => Array
(
[0] => Array
(
[host_name] => localhost
[current_state] => 0
[service_id] => 158
)
[1] => Array
(
[host_name] => localhost
[current_state] => 0
[service_id] => 159
)
)
[192.168.0.43] => Array
(
[0] => Array
(
[host_name] => 192.168.0.43
[current_state] => 0
[service_id] => 168
)
[1] => Array
(
[host_name] => 192.168.0.43
[current_state] => 1
[service_id] => 162
)
)
)
So Array3 should be:
Array3
(
[localhost] => Array
(
[0] => Array
(
[host_name] => localhost
[current_state] => 0
[service_id] => 158
)
[192.168.0.43] => Array
(
[0] => Array
(
[host_name] => 192.168.0.43
[current_state] => 0
[service_id] => 162
)
)
)
Here is what I have so far, but it doesn't appear to be filtering the entire array.
$Array3= array_filter($Array2, function ($value) use ($Array1) {
return in_array(array_shift($value)['service_id'], $Array1);
});
Am I close here, What am I missing?