LoginSignup
0

More than 1 year has passed since last update.

【PHP】 Range関数に第三引数あったんやね

Last updated at Posted at 2022-09-28

第三引数step

指定した範囲の数字配列を作る時にrangeをよく使います。

第三引数で2づつ増える、3づつ減るなどを指定できるようでした。

昇順
$ranges = range(1,100,2);

array:50 [
  0 => 1
  1 => 3
  2 => 5
  3 => 7
  4 => 9
  5 => 11
  6 => 13
  7 => 15
  8 => 17
  9 => 19
  10 => 21
  11 => 23
  12 => 25
......
]
降順
$ranges = range(100,1,-3);

array:34 [
  0 => 100
  1 => 97
  2 => 94
  3 => 91
  4 => 88
  5 => 85
  6 => 82
  7 => 79
  8 => 76
......
]

第三引数、-数値でも+数値でも挙動が変わらなかった。

第三引数あったの知らなかった

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