Display results from a search of an array in another

0

I think my question is simple, I have 2 arrays, one that stores the MACs of the equipment being consulted ($ cmdarr) and another that stores the concentrator MACs ) , I want to find the occurrences of the first $ cmdarr array in the second $ ips and display only the [name] field of the occurrences found.

print_r($cmdarr);
print_r($ips);

Array
(
    [0] => Array
        (
            [0] => 00:1A:3F:6D:3D:C5
            [1] => 00:1A:3F:6D:69:49
            [2] => 
        )

)
Array
(
    [0] => Array
        (
            [.id] => *80003470
            [name] => 47460
            [service] => pppoe
            [caller-id] => 00:1A:3F:64:3C:B5
            [address] => 179.189.141.238
            [uptime] => 14h57m8s
            [encoding] => 
            [session-id] => 0x81903470
            [limit-bytes-in] => 0
            [limit-bytes-out] => 0
            [radius] => true
        )
    
asked by anonymous 06.06.2017 / 23:16

1 answer

2

A foreach solves your problem:

foreach ($ips as $ip) {
    if (in_array($ip['caller-id'], $cmdarr[0])) {
        echo "{$ip['name']}\r\n";
    }
}
    
07.06.2017 / 06:03