S
S
Sergey Druzhko2018-07-20 23:31:04
PHP
Sergey Druzhko, 2018-07-20 23:31:04

How to find values ​​in an array from another array?

There is an array

array(4) {
  [377091727]=>
  int(1)
  [497733563]=>
  int(2)
  [292182390]=>
  int(3)
  [140594439]=>
  int(4)
}

and an array
array(1) {
  ["response"]=>
  array(2) {
    ["count"]=>
    int(108)
    ["items"]=>
    array(113) {
      [0]=>
      array(4) {
        ["type"]=>
        string(7) "profile"
        ["uid"]=>
        int(363719724)
        ["first_name"]=>
        string(3) "Tim"
        ["last_name"]=>
        string(5) "Zubov"
      }
      [1]=>
      array(4) {
        ["type"]=>
        string(7) "profile"
        ["uid"]=>
        int(292182390)
        ["first_name"]=>
        string(8) "Вася"
        ["last_name"]=>
        string(14) "Петрова"
      }
      [2]=>
      array(4) {
        ["type"]=>
        string(7) "profile"
        ["uid"]=>
        int(318201765)
        ["first_name"]=>
        string(6) "Azamat"
        ["last_name"]=>
        string(13) "Gilyazetdinov"
      }
      [3]=>
      array(4) {
        ["type"]=>
        string(7) "profile"
        ["uid"]=>
        int(290122847)
        ["first_name"]=>
        string(8) "Илья"
        ["last_name"]=>
        string(8) "Гаев"
      }
      [4]=>
      array(4) {
        ["type"]=>
        string(7) "profile"
        ["uid"]=>
        int(377091727)
        ["first_name"]=>
        string(12) "Андрій"
        ["last_name"]=>
        string(14) "Конопля"
      }
      [5]=>
      array(4) {
        ["type"]=>
        string(7) "profile"
        ["uid"]=>
        int(140594439)
        ["first_name"]=>
        string(12) "Андрей"
        ["last_name"]=>
        string(16) "Белицкий"
      }
      [6]=>
      array(4) {
        ["type"]=>
        string(7) "profile"
        ["uid"]=>
        int(377091727)
        ["first_name"]=>
        string(8) "Влад"
        ["last_name"]=>
        string(10) "Щепин"
      }
      [7]=>
      array(4) {
        ["type"]=>
        string(7) "profile"
        ["uid"]=>
        int(497733563)
        ["first_name"]=>
        string(8) "Иван"
        ["last_name"]=>
        string(16) "Ситников"
      }
      [8]=>
      array(4) {
        ["type"]=>
        string(7) "profile"
        ["uid"]=>
        int(227856960)
        ["first_name"]=>
        string(12) "Максим"
        ["last_name"]=>
        string(16) "Леонтьев"
      }
      [9]=>
      array(4) {
        ["type"]=>
        string(7) "profile"
        ["uid"]=>
        int(290520411)
        ["first_name"]=>
        string(8) "Влад"
        ["last_name"]=>
        string(14) "Пикусев"
      }
      [10]=>
      array(4) {
        ["type"]=>
        string(7) "profile"
        ["uid"]=>
        int(151993364)
        ["first_name"]=>
        string(12) "Максим"
        ["last_name"]=>
        string(16) "Харченко"
      }
      [11]=>
      array(4) {
        ["type"]=>
        string(7) "profile"
        ["uid"]=>
        int(292182390)
        ["first_name"]=>
        string(8) "Лёха"
        ["last_name"]=>
        string(12) "Минаев"
      }
      [12]=>
      array(4) {
        ["type"]=>
        string(7) "profile"
        ["uid"]=>
        int(171322495)
        ["first_name"]=>
        string(8) "Саша"
        ["last_name"]=>
        string(20) "Екатеринин"
      }
      [13]=>
      array(4) {
        ["type"]=>
        string(7) "profile"
        ["uid"]=>
        int(415914759)
        ["first_name"]=>
        string(10) "Тимур"
        ["last_name"]=>
        string(12) "Азимов"
      }
      }
    }
  }
}

How to remove values ​​from the first array that are not in the second "uid" array

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Viktor Yanyshev, 2018-07-20
@leave_me_here

foreach($arr2['response']['items'] as $item) {
   if(!$arr2[$item['uid']) unset($arr2[$item['uid']);
}

P
petyagrill, 2018-07-20
@petyagrill

array_intersect should do the job .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question