Display results of a search for an array in another

Asked

Viewed 31 times

0

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

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
        )

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";
    }
}
  • 1

    One addition I would make is to change the fixed comparison in position $cmdarr[0] by another foreach and in making the comparison.

  • Thanks buddy, that’s exactly what I was looking for, settled the question!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.