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 3 years have passed since last update.

array_diff()ってなんやねん!!

Last updated at Posted at 2020-11-07

array_diff()ってなんやねん!!
##説明
array_diff()は、

array_diff ( array $array1 , array $array2 [, array $... ] )

第一引数にかかれている関数を、そのほかの関数と比べて差分を抽出する。
(個人的には配列1から配列2を引くって感じ)

$array1 = [1,2,3,4,5,6,7,8,9,11,12,13,22,22];
$array2 = [1,22,50]
$array = array_diff($array1, $array2);
var_dump($array);

array1にarray2の要素があれば消す。(差分を出す)

2,3,4,5,6,7,8,9,11,12,13

##実際に使ったのはこんな感じ

$tehai_array = [1,2,3,4,5,6,7,8,9,11,12,13,22,22];
$head_candidate = [22]
$except = array_diff($tehai_array, $head_candidate);
var_dump($except);
1,2,3,4,5,6,7,8,9,11,12,13

が出力される。(22がなくなる。)

#筆者
2020年1月ごろからプログラミング学習し始めました。
日々の学習についてあげています。
麻雀点数計算アプリを作成中!!!
不備があればご指摘いただければ幸いです。

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?