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

PHP
php 无限分类的实现
常用PHP代码
windows下安装配置php视频教程
MySQL数据库结构和数据的导出和导入
PHP实现 IP Whois 查询
PHP5 this,self和parent关键字详解
PHP 安全技巧连载 #1[译]
PHP 安全技巧连载 #2[译]
PHP 安全技巧连载 #3[译]
PHP 安全技巧连载 #4[译]
PHP 安全技巧连载 #5[译]
PHP 安全技巧连载 #6[译]
PHP 安全技巧连载 #7[译]
PHP 安全技巧连载 #8[译]
PHP 安全技巧连载 #9[译]
PHP 安全技巧连载 #10[译]
PHP 安全技巧连载 #11[译]
PHP error_reporting的使用
PHP 安全技巧连载 #12
使用PHP做Linux/Unix守护进程

PHP 中的 range() 函数


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-04   浏览: 478 ::
收藏到网摘: 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

登陆 | 还没注册?