Home > Backend Development > PHP Tutorial > PHP method to generate an array based on a given range and step, PHP gives a step array_PHP tutorial

PHP method to generate an array based on a given range and step, PHP gives a step array_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-13 09:49:31
Original
1224 people have browsed it

php method to generate an array based on a given range and step, php gives a step array

The start and end values ​​are given here, and a step value is given , you can generate an arithmetic array.

function array_range($from, $to, $step=1){
  $array = array();
  for ($x=$from; $x <= $to; $x += $step){
    $array[] = $x;
  }
  return $array;
}
print_r(array_range(0, 20, 5));
/*
returns:
Array
(
  [0] => 0
  [1] => 5
  [2] => 10
  [3] => 15
  [4] => 20
)
*/

Copy after login

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1019451.htmlTechArticlephp method to generate an array based on a given range and step, php gives a step array and the start is given here and the end value, and given a step value, an arithmetic array can be generated. f...
Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template