PHP 生成连续的数字(字母)数组函数range()分析,PHP抽奖程序函数

WBOY
Release: 2016-06-20 13:05:17
Original
2376 people have browsed it

本篇文章主要介绍的是php数组函数rang的用法,对于抽奖类的应用,文章末尾有举例说明。

PHP函数range()快速创建数组的方法比如range()函数可以快速创建从1到9的数字数组:

$numbers=range(1,9);//用range直接创建1-9且1开头9结束的共9个数字组成的数组

$numbers=range(1,9);//用range创建了9到1的且9开头1结束的数字数组另外PHP函数range()还可以创建从a到z的或A到Z的字符数组,用法同上。

PHP函数range()还具有第三个参数,该参数的作用是设定步长,比如range(1,9,3)创建的数组元素是:1、4、7。

注意:PHP函数range()在创建数组的时候是区别大小写的,比如range(A,z)和range(a,Z)是不一样的。

在数组中随意取出一个或多个元素的键名方法可使用PHP函数array_rand语法 array_rand(array,number)array必需。规定输入的数组参数。

number可选。

默认是 1。规定返回多少个随机的元素。如果number是1,则只返回一个字符串类型的键名,如果number大于1,则返回的是包含随机键名的数组。


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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!