1

I have two multidimensional arrays

$array1 = Array (
   [a1] => Array  (
           [a_name] => aaaaa
           [a_value] => aaa
         )

   [b1] => Array (
           [b_name] => zzzzz
           [b_value] => bbb
       )
   [c1] => Array (
           [c_name] => ccccc
           [c_value] => ccc
       )

 )

$array2 = Array (
     [b1] => Array (
           [b_name]=> zzzzz
         )
  );

Here i want to append both if array2 match value is equal to array1 with key and value, i.e, both are matching or both are not matching within array2

function recursive_array_intersect_key(array $array1, array $array2) {
    $array1 = array_intersect_key($array1, $array2);
    foreach ($array1 as $key => &$value) {
        if (is_array($value) && is_array($array2[$key])) {
            $value = recursive_array_intersect_key($value, $array2[$key]);
        }
    }
    return $array2;
}

Expectet output as if array2 matched with array2

 $array2 = Array (
         [b1] => Array (
               [b_name]=> zzzzz
             ),
         [status] => Both Matched
      );

or for not matched array2 with array2

$array2 = Array (
         [b1] => Array (
               [b_name]=> zzzzz
             ),
         [status] => Not Matched
      );
  • Can you show an example of the output you need for the intersection of those two arrays? And can you explain what's going on with your code there? Is that code that tries to do the intersection and doesn't work? If so, what goes wrong? Does it produce the wrong output? No output? Are there errors? – Don't Panic Aug 22 '18 at 19:05
  • Hi @Don'tPanic, i am big fan for you, here is the link https://stackoverflow.com/questions/12171855/multidimensional-associative-array-intersection-php i am working similar to this, but here i want return array2 with key as status and value as match or not match – VijayaKrishna Aug 22 '18 at 19:10
  • Something so: https://eval.in/1050047 ? – splash58 Aug 22 '18 at 19:26
  • @splash58, thank you, exactly what i am looking for, can you answer this question and explain briefly, how to working similar problem in array in futuer, this might some one might help ful – VijayaKrishna Aug 22 '18 at 19:30

0 Answers0