Answers for "get the matched value from 2 multidimensional array in php by id"

PHP
0

get the matched value from 2 multidimensional array in php by id

<?php
  $a = Array(
      Array('id' => 1, 'affiliate_id' => 190),
      Array('id' => 2, 'affiliate_id' => 946)
  );

  $b = Array(
      Array('id' => 1, 'user_id' => 190),
      Array('id' => 2, 'user_id' => 246),
      Array('id' => 3, 'user_id' => 249),
      Array('id' => 3, 'user_id' => 250)
  );

  $c = array_map(function ($arr) { return $arr['affiliate_id']; }, $a);
  $d = array_map(function ($arr) { return $arr['user_id']; }, $b);

  $e = array_intersect($c, $d);

  // Output
  // Array ( [0] => 190 )

?>
Posted by: Guest on August-18-2021

Code answers related to "get the matched value from 2 multidimensional array in php by id"

Browse Popular Code Answers by Language