search
LoginSignup
102

More than 5 years have passed since last update.

posted at

updated at

PHP - foreachで最初と最後の処理を制御する

$array = [1, 2, 3, 4, 5];
foreach ($array as $value) {
    if ($value === reset($array)) {
        // 最初
    }
    if ($value === end($array)) {
        // 最後
    }
}

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
What you can do with signing up
102