fork download
  1. <?php
  2.  
  3. $array1 = array(
  4. (object) array("id" => 1),
  5. (object) array("id" => 3),
  6. (object) array("id" => 5),
  7. (object) array("id" => 6),
  8. (object) array("id" => 7)
  9. );
  10.  
  11. $array2 = array(
  12. (object) array("id" => 1),
  13. (object) array("id" => 3),
  14. (object) array("id" => 5),
  15. (object) array("id" => 6),
  16.  
  17. );
  18.  
  19. $array3 = array();
  20. foreach($array2 as $t) {
  21. $array3[] = $t->id;
  22. }
  23. $result = array_filter($array1, function($v) use($array3){
  24. return in_array($v->id, $array3);
  25. });
  26. print_r($result);
Success #stdin #stdout 0.02s 82560KB
stdin
Standard input is empty
stdout
Array
(
    [0] => stdClass Object
        (
            [id] => 1
        )

    [1] => stdClass Object
        (
            [id] => 3
        )

    [2] => stdClass Object
        (
            [id] => 5
        )

    [3] => stdClass Object
        (
            [id] => 6
        )

)