0

I have two dimension array and want to get only same value in another array. In the following array I have 196 two times in keywords array and 1 in array degree. I would to get number 196 in an another array.

Array(
    [keywords] => Array (
        [0] => 196
        [1] => 196
        [2] => 520
        [3] => 366
        [4] => 521
        [5] => 934
        [6] => 530
        [7] => 529
        [8] => 487
        [9] => 486
        [10] => 484
        [11] => 483
        [12] => 376
        [13] => 223
    )

    [degree] => Array (
        [0] => 519
        [1] => 196
    )
)

I want array like

  result (
      ["WANTED"] = 196
      );
  • 1
    Possible duplicate of [How to get common values from two different arrays in PHP](https://stackoverflow.com/questions/17648962/how-to-get-common-values-from-two-different-arrays-in-php) – Mittul At TechnoBrave Jun 22 '17 at 11:03
  • $var['degree'][1] – Martin Kuchyňár Jun 22 '17 at 11:03
  • possible duplicate of https://stackoverflow.com/questions/8679420/checking-if-2-arrays-have-atleast-1-equal-value – Nirav Joshi Jun 22 '17 at 11:04
  • Possible duplicate of [PHP - Merging two array into one array (also Remove Duplicates)](https://stackoverflow.com/questions/13469803/php-merging-two-array-into-one-array-also-remove-duplicates) – Benny Jun 22 '17 at 11:14

1 Answers1

0
<?php 
    $abc=array();
    $abc=['keywords'=>[196,215,520,366,780,820,999,867,215],'degree'=>
    ['999','820','366']];
    $result=[];
    $result['WANTED']=(array_intersect($abc['keywords'],$abc['degree']));
    print_r($result);
?>
Bhargav Chudasama
  • 6,928
  • 5
  • 21
  • 39