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 |