Home > Backend Development > PHP Tutorial > The range function in php creates an array containing cells in the specified range

The range function in php creates an array containing cells in the specified range

WBOY
Release: 2016-07-25 08:57:30
Original
1369 people have browsed it
This article introduces an example of using the range function in PHP to create an array containing cells in a specified range. Friends in need can refer to it. Previously, we introduced an article on how to quickly create an array in PHP, in which the PHP range() function was used.

This article introduces an example of using the range function in PHP to create an array containing cells in a specified range. Friends in need can refer to it.

Before, we introduced an article on how to quickly create an array in PHP, in which the PHP range() function was used. You can refer to it as a warm-up for this article. In this section, we learn how to use the range() function in PHP.

Example:

<?php
/**
* range()函数用法
* edit by bbs.it-home.org
*/
    //输出:cegikmoqsuwy
    foreach ( range( c,z, 2 ) as $f ){
        echo $f;
    }   
                            
    //输出:12345678910
    foreach ( range( 1,10 ) as $f ){
        echo $f;
    }
                            
    //输出:100908070605040302010
    foreach ( range( 100,1,10 ) as $f ){
        echo $f;
    }
?>
Copy after login

Instructions: array range(mixed $start , mixed $limit [, number $step = 1 ]); $start: sequence starting value $limit: sequence end value $step: step value; optional, default is 1; If the value is the same as $start, an error will be reported: Warning: range() [function.range]: step exceeds the specified range in /file position on line how many lines For example:

<?php
foreach ( range( 100,1,100 ) as $f ){
   echo $f;
}
?>
Copy after login

For specific usage of the range() function, please refer to the article: http://bbs.it-home.org/w3school/php/func_array_range.html



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