array_diff() and with named arrays


$a1 = array("1", "2");
$a2 = array(array("numbers" => "1", "something else" => "foo"), array("numbers" => "2", "something else" => "bar"));

I need to compare $a1 to $a2 numbers.

I dont… understand?

What output do you desire?

Assumption: You mean you want any values of $a2 whose number element does not exist in $a1;

Something like…

$a3 = array_filter($a2,function ($item) { return !in_array($item['number'],$a1); });

, perhaps?
(Note: Untested)

No way to use array_diff? I want anything in $a1 that does not exist in $a2[‘numbers’]

but values 1 and 2 DO exist in $a2
do you mean you want to return any values in $a2 that don’t exist in $a1

if so,

this might help:

$a1 = array("1", "2");
$a2 = array(array("numbers" => "1", "something else" => "foo"), array("numbers" => "2", "something else" => "bar"));
$a3 = array_merge_recursive(array_diff($a2[0],$a1),array_diff($a2[1],$a1));

echo '<pre>';
print_r($a3);
echo '</pre>';

returns:

Array
(
    [something else] => Array
        (
            [0] => foo
            [1] => bar
        )

)

Well, sort of i suppose.

array_diff($a1,array_map(function($item) { return $item['numbers']; },$a2));

Essentially reduce $a2 to the array of it’s number elements, and then diff it.

EDIT: Helps if i put the parameters in the correct order.