shin
shin

Reputation: 32721

How to find array items which is not in other array

I have two arrays as follows. And I want to pick up names from dir_info array which are not in templates['name']

In this case I want to pick up redrose.

Can anyone suggest how to do it?

Thanks in advance.

templates: Array
(
    [0] => Array
        (
            [id] => 1
            [name] => default
            [default] => 1
        )

    [1] => Array
        (
            [id] => 2
            [name] => bluenote
            [default] => 0
        )

    [2] => Array
        (
            [id] => 3
            [name] => redhat
            [default] => 0
        )

)


dir_info: Array
(
    [default] => Array
        (
            [name] => default
            ...
        )

    [redhat] => Array
        (
            [name] => redhat
          ...
        )

    [redrose] => Array
        (
            [name] => redrose
            ...
        )

)

Upvotes: 0

Views: 64

Answers (1)

hsz
hsz

Reputation: 152294

$templates; $dir_info; // your arrays

$output = $dir_info;
foreach ( $templates as $template ) {
  unset($output[$template['name']]);
}

$output; // filtered $dir_info array

Upvotes: 4

Related Questions