当前位置: 首页 > 网络学院 > 服务端脚本教程 > PHP > range() 函数

PHP
PHP 安全邮件
MySQL 介绍
连接 MySQL
创建 MySQL
MySQL 插入记录
MySQL 选择记录
MySQL Where
MySQL Order By
MySQL 记录更新
MySQL 删除记录
PHP ODBC
XML Expat Parser
XML SimpleXML
PHP 数组参考
PHP Calendar
PHP Date
PHP Directory
PHP Filesystem
PHP FTP
PHP HTTP

PHP 中的 range() 函数


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-04   浏览: 477 ::
收藏到网摘: n/a

Definition and Usage
定义和用法

The range() function creates an array containing a range of elements.
range()函数的作用是:创建一个包含指定范围元素的数组

This function returns an array of elements from low to high.
这个函数将按照从低(小)到高(大)的顺序返回数组元素。

Syntax
语法

range(low,high,step)

Parameter
参数
Description
描述
low Required. Specifies the lowest value of the array
必要参数。指定数组中的最小值
high Required. Specifies the highest value of the array
必要参数。指定数组中的最大值
step Optional. Specifies the increment used in the range. Default is 1
 可选参数。指定增量,默认值为1

Note: This parameter was added in PHP 5
注意:这个参数只在PHP 5以上版本中支持



Tips and Notes
提示和注意点

Note: If the low parameter is higher than the high parameter, the range array will be from high to low.
注意:如果你设定的最小参数[low parameter]比数组中最大的参数还要大,那么将按照从高(大)到低(小)的顺序输出元素。


Example 1
案例1

<?php
$number = range(0,5);
print_r ($number);
?>

The output of the code above will be:
上述代码将输出下面的结果:

Array
(
[0] => 0
[1] => 1
[2] => 2
[3] => 3
[4] => 4
[5] => 5
) 


Example 2
案例2

<?php
$number = range(0,50,10);
print_r ($number);
?>

The output of the code above will be:
上述代码将输出下面的结果:

Array
(
[0] => 0
[1] => 10
[2] => 20
[3] => 30
[4] => 40
[5] => 50
)


Example 3
案例3

<?php
$letter = range("a","d");
print_r ($letter);
?>

The output of the code above will be:
上述代码将输出下面的结果:

Array
(
[0] => a
[1] => b
[2] => c
[3] => d
) 

评论 (0) All

登陆 | 还没注册?