Home >Backend Development >PHP Tutorial >Create array using range function
The content of this article is about using the range function to create arrays. It has certain reference value. Now I share it with you. Friends in need can refer to it
Array traversal language
--Quickly create an array
--range(1,5)
What does this range function mean? Who is the key? Who is worth it? Range is a
function that quickly creates arrays. The functions provided by PHP to quickly create arrays include range(), explode(),
array_combine(), array_fill() and array_pad(). Don't understand the rest of the functions
. Focus on the range() function.
Syntax format, arrge range(mixed start,mixed end)
Function function: Quickly create a numeric array or character array ranging from start to end.
Note that if start>end, the sequence will be in descending order from start to end.
Come, let’s give an example,
<?php $numbers = range(1,5); //一个叫做numbers的数组,里面有五个值。array(1,2,3,4,5) print_r($numbers); /*输出,array( [0]=>1 [1]=>2 [2]=>3 [3]=>4 [4]=>5) *前面是键,后面是值 /* //如果是字符串怎么办?就不是数字了 $chars1 = range('a','d');//chars是字符。开始序列是a,结束序 列是d print_r($chars1); /*输出数组里面的值。 *array( [0]=>a [1]=>b [2]=>c [3]=>d) */ ?>
Summary, create an array, and then traverse the array. The limitation can only be a regular sequence. If there are no
rules, there is nothing you can do.
The above is the detailed content of Create array using range function. For more information, please follow other related articles on the PHP Chinese website!