Compare two associative arrays and create a new array with the matched arrays, PHP
Posted
by user194630
on Stack Overflow
See other posts from Stack Overflow
or by user194630
Published on 2010-05-21T12:18:19Z
Indexed on
2010/05/21
12:20 UTC
Read the original article
Hit count: 349
I have this two arrays:
$arr1=array( array("id" => 8, "name" => "test1"),
array("id" => 4, "name" => "test2"),
array("id" => 3, "name" => "test3")
);
$arr2=array( array("id" => 3),
array("id" => 4)
);
How can i "extract" arrays from $arr1, where id have same value in $arr2, into a new array and leave the extracted array also in a new array, without taking into account key orders?
The output i am looking for should be:
$arr3=array(
array("id" => 8, "name" => "test1")
);
$arr4=array( array("id" => 4, "name" => "test2"),
array("id" => 3, "name" => "test3")
);
Thanks
© Stack Overflow or respective owner