0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【PHP】PHPの配列比較。array_intersect(アレイインターセクト)を使う

Last updated at Posted at 2023-09-22

コード

<?php
$data = [
    ['1','2','3','4','5']
   ,['88','288','83','84','85']
   ,['1','2','3','4','5']
];


$search = ['1','2','266'] ;

foreach ($data as $value){
   if(array_intersect($search,$value)){
        echo true;
    }else{
        echo 'false';
    }
}

結果1

array(2) {
  [0]=>
  string(1) "1"
  [1]=>
  string(1) "2"
}
array(0) {
}

結果2

array(0) {
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?