3
1

More than 1 year has passed since last update.

配列の要素の重複値を取り除く(PHP)

Posted at

PHPで配列の要素の重複値を取り除く処理です
PHPのarray_unique関数を使います

<?php
    $array1 = ['cat','dog','cat','rabbit','bear'];
    // 重複値を取り除くため、array_unique関数を使う。
    $array2 = array_unique($array1);
    // preタグで囲んでprint_r関数の出力結果を見やすくする。
    echo "<pre>";
    print_r($array2);
    echo "</pre>";
?>

以上の方法を使うとよいでしょう。
preタグは配列の出力結果を見やすくするために使用します。

3
1
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
3
1