How to use range function

藏色散人
Release: 2023-04-05 07:02:01
Original
24283 people have browsed it

The range function is to create an array containing elements in a specified range. The syntax for using this function is "range(low,high,step)", where the parameter low specifies the minimum value of the array, and the parameter high specifies The highest value of the array, the parameter step specifies the step system between elements.

How to use range function

The operating environment of this article: Windows 7 system, Dell G3 computer, PHP version 7.1.

PHP range() function is used to create an array based on a range, containing specified elements.

php range() function syntax

Function: Create an array containing elements in the specified range

Syntax:

range(low,high,step)
Copy after login

Parameters:

low Required. Specifies the minimum value of the array.

high Required. Specifies the maximum value of the array.

step Optional. Specifies the stepping between elements. The default is 1.

Description: This function creates an array containing integers or characters from low to high (including low and high). If high is smaller than low, return the array in reverse order.

php range() function example

<?php
$number = range(1,6);
print_r ($number);
?>
Copy after login

Output:

Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 )
Copy after login

php range() function example

<?php
$str = range(&#39;b&#39;,&#39;e&#39;);
print_r ($str);
?>
Copy after login

Output:

Array ( [0] => b [1] => c [2] => d [3] => e )
Copy after login

This article is an introduction to the PHP range function. I hope it will be helpful to friends in need!

The above is the detailed content of How to use range function. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template