LoginSignup
1
2

More than 5 years have passed since last update.

【PHP】foreachで繰り返す回数を指定する

Last updated at Posted at 2018-05-07
$i=0;
foreach ($array as $key => $value) {

    if($i>count($array)){
        break;
    }

    if ($array[$key]==$array[$key+1]) {
        unset($array[$key]);
    }

    $i++;

}

たとえば、多次元配列内で重複する要素がある場合、その要素を削除したい場合などに利用できます。

1
2
2

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