php笔记之:php函数range() round()和list()的使用说明

前端之家收集整理的这篇文章主要介绍了php笔记之:php函数range() round()和list()的使用说明前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

<P style="WIDOWS: 2; TEXT-TRANSFORM: none; TEXT-INDENT: 0px; FONT: 14px/21px 宋体,Verdana,Arial,Helvetica,sans-serif; WHITE-SPACE: normal; ORPHANS: 2; LETTER-SPACING: normal; COLOR: #000000; WORD-SPACING: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">

<FONT style="COLOR: #ff0000">一>>


<P style="WIDOWS: 2; TEXT-TRANSFORM: none; TEXT-INDENT: 0px; FONT: 14px/21px 宋体,sans-serif; WHITE-SPACE: normal; ORPHANS: 2; LETTER-SPACING: normal; COLOR: #000000; WORD-SPACING: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">range()函数快速创建数组的简单方法,使用low到high范围的整数值填充数组,函数将返回一个包含次范围内所有整数的数组.形式如下


<P style="WIDOWS: 2; TEXT-TRANSFORM: none; TEXT-INDENT: 0px; FONT: 14px/21px 宋体,sans-serif; WHITE-SPACE: normal; ORPHANS: 2; LETTER-SPACING: normal; COLOR: #000000; WORD-SPACING: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">array range(int low,int high[,int step])


<P style="WIDOWS: 2; TEXT-TRANSFORM: none; TEXT-INDENT: 0px; FONT: 14px/21px 宋体,sans-serif; WHITE-SPACE: normal; ORPHANS: 2; LETTER-SPACING: normal; COLOR: #000000; WORD-SPACING: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">

典型用法如下


<P style="WIDOWS: 2; TEXT-TRANSFORM: none; TEXT-INDENT: 0px; FONT: 14px/21px 宋体,sans-serif; WHITE-SPACE: normal; ORPHANS: 2; LETTER-SPACING: normal; COLOR: #000000; WORD-SPACING: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">例子:建立1-6的6个数字的数组(骰子)


<P style="WIDOWS: 2; TEXT-TRANSFORM: none; TEXT-INDENT: 0px; FONT: 14px/21px 宋体,sans-serif; WHITE-SPACE: normal; ORPHANS: 2; LETTER-SPACING: normal; COLOR: #000000; WORD-SPACING: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">$die = range(0,6);


<P style="WIDOWS: 2; TEXT-TRANSFORM: none; TEXT-INDENT: 0px; FONT: 14px/21px 宋体,sans-serif; WHITE-SPACE: normal; ORPHANS: 2; LETTER-SPACING: normal; COLOR: #000000; WORD-SPACING: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">建立0-30所有双数的数组


<P style="WIDOWS: 2; TEXT-TRANSFORM: none; TEXT-INDENT: 0px; FONT: 14px/21px 宋体,sans-serif; WHITE-SPACE: normal; ORPHANS: 2; LETTER-SPACING: normal; COLOR: #000000; WORD-SPACING: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">$even = (0,20,2);//步长为2


<P style="WIDOWS: 2; TEXT-TRANSFORM: none; TEXT-INDENT: 0px; FONT: 14px/21px 宋体,sans-serif; WHITE-SPACE: normal; ORPHANS: 2; LETTER-SPACING: normal; COLOR: #000000; WORD-SPACING: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">

这个函数不仅仅可以用作数字,还可以用作字母.


<P style="WIDOWS: 2; TEXT-TRANSFORM: none; TEXT-INDENT: 0px; FONT: 14px/21px 宋体,sans-serif; WHITE-SPACE: normal; ORPHANS: 2; LETTER-SPACING: normal; COLOR: #000000; WORD-SPACING: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">


<P style="WIDOWS: 2; TEXT-TRANSFORM: none; TEXT-INDENT: 0px; FONT: 14px/21px 宋体,sans-serif; WHITE-SPACE: normal; ORPHANS: 2; LETTER-SPACING: normal; COLOR: #000000; WORD-SPACING: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">$words = range('A','Z');


<P style="WIDOWS: 2; TEXT-TRANSFORM: none; TEXT-INDENT: 0px; FONT: 14px/21px 宋体,sans-serif; WHITE-SPACE: normal; ORPHANS: 2; LETTER-SPACING: normal; COLOR: #000000; WORD-SPACING: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">将建立包含A到Z的的所有字母的数组.此处可以用于生成验证码函数.


<P style="WIDOWS: 2; TEXT-TRANSFORM: none; TEXT-INDENT: 0px; FONT: 14px/21px 宋体,sans-serif; WHITE-SPACE: normal; ORPHANS: 2; LETTER-SPACING: normal; COLOR: #000000; WORD-SPACING: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">

<FONT style="COLOR: #ff0000">二>>


<P style="WIDOWS: 2; TEXT-TRANSFORM: none; TEXT-INDENT: 0px; FONT: 14px/21px 宋体,sans-serif; WHITE-SPACE: normal; ORPHANS: 2; LETTER-SPACING: normal; COLOR: #000000; WORD-SPACING: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">round()函数


<P style="WIDOWS: 2; TEXT-TRANSFORM: none; TEXT-INDENT: 0px; FONT: 14px/21px 宋体,sans-serif; WHITE-SPACE: normal; ORPHANS: 2; LETTER-SPACING: normal; COLOR: #000000; WORD-SPACING: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">这个函数是怕我记混淆了.这个函数和上面的哪个range()是天壤之别.


<P style="WIDOWS: 2; TEXT-TRANSFORM: none; TEXT-INDENT: 0px; FONT: 14px/21px 宋体,sans-serif; WHITE-SPACE: normal; ORPHANS: 2; LETTER-SPACING: normal; COLOR: #000000; WORD-SPACING: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">这个函数的作用是


<P style="WIDOWS: 2; TEXT-TRANSFORM: none; TEXT-INDENT: 0px; FONT: 14px/21px 宋体,sans-serif; WHITE-SPACE: normal; ORPHANS: 2; LETTER-SPACING: normal; COLOR: #000000; WORD-SPACING: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">取浮点数的精度


<P style="WIDOWS: 2; TEXT-TRANSFORM: none; TEXT-INDENT: 0px; FONT: 14px/21px 宋体,sans-serif; WHITE-SPACE: normal; ORPHANS: 2; LETTER-SPACING: normal; COLOR: #000000; WORD-SPACING: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">float round(float var[,int preisin})


<P style="WIDOWS: 2; TEXT-TRANSFORM: none; TEXT-INDENT: 0px; FONT: 14px/21px 宋体,sans-serif; WHITE-SPACE: normal; ORPHANS: 2; LETTER-SPACING: normal; COLOR: #000000; WORD-SPACING: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">

<FONT style="COLOR: #ff0000">典型用法


<P style="WIDOWS: 2; TEXT-TRANSFORM: none; TEXT-INDENT: 0px; FONT: 14px/21px 宋体,sans-serif; WHITE-SPACE: normal; ORPHANS: 2; LETTER-SPACING: normal; COLOR: #000000; WORD-SPACING: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">例: $pi = 3.141592653;


<P style="WIDOWS: 2; TEXT-TRANSFORM: none; TEXT-INDENT: 0px; FONT: 14px/21px 宋体,sans-serif; WHITE-SPACE: normal; ORPHANS: 2; LETTER-SPACING: normal; COLOR: #000000; WORD-SPACING: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">round($pi,4);


<P style="WIDOWS: 2; TEXT-TRANSFORM: none; TEXT-INDENT: 0px; FONT: 14px/21px 宋体,sans-serif; WHITE-SPACE: normal; ORPHANS: 2; LETTER-SPACING: normal; COLOR: #000000; WORD-SPACING: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">echo $pi;


<P style="WIDOWS: 2; TEXT-TRANSFORM: none; TEXT-INDENT: 0px; FONT: 14px/21px 宋体,sans-serif; WHITE-SPACE: normal; ORPHANS: 2; LETTER-SPACING: normal; COLOR: #000000; WORD-SPACING: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">将输出 3.1415


<P style="WIDOWS: 2; TEXT-TRANSFORM: none; TEXT-INDENT: 0px; FONT: 14px/21px 宋体,sans-serif; WHITE-SPACE: normal; ORPHANS: 2; LETTER-SPACING: normal; COLOR: #000000; WORD-SPACING: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">

<FONT style="COLOR: #ff0000">三>>


<P style="WIDOWS: 2; TEXT-TRANSFORM: none; TEXT-INDENT: 0px; FONT: 14px/21px 宋体,sans-serif; WHITE-SPACE: normal; ORPHANS: 2; LETTER-SPACING: normal; COLOR: #000000; WORD-SPACING: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">list()函数


<P style="WIDOWS: 2; TEXT-TRANSFORM: none; TEXT-INDENT: 0px; FONT: 14px/21px 宋体,sans-serif; WHITE-SPACE: normal; ORPHANS: 2; LETTER-SPACING: normal; COLOR: #000000; WORD-SPACING: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">list()函数可以在一次操作中从一个数组内提取多个值.同时为变量赋值.形式如下


<P style="WIDOWS: 2; TEXT-TRANSFORM: none; TEXT-INDENT: 0px; FONT: 14px/21px 宋体,sans-serif; WHITE-SPACE: normal; ORPHANS: 2; LETTER-SPACING: normal; COLOR: #000000; WORD-SPACING: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">void list(mixed)


<P style="WIDOWS: 2; TEXT-TRANSFORM: none; TEXT-INDENT: 0px; FONT: 14px/21px 宋体,sans-serif; WHITE-SPACE: normal; ORPHANS: 2; LETTER-SPACING: normal; COLOR: #000000; WORD-SPACING: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">

典型用法


<DIV style="WIDOWS: 2; TEXT-TRANSFORM: none; TEXT-INDENT: 0px; FONT: 14px/21px 宋体,sans-serif; WHITE-SPACE: normal; ORPHANS: 2; LETTER-SPACING: normal; COLOR: #000000; WORD-SPACING: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">

Highlighter_701768 class="SyntaxHighlighter nogutter PHP ie">
PHP plain">
代码如下:
PHP $info = array('coffee','brown','caffeine'); // Listing all the variables
list($drink,$color,$power) = $info;
echo "$drink is $color and $power makes it special.\n"; // Listing some of them
list($drink,$power) = $info;
echo "$drink has $power.\n"; // Or let's skip to only the third one
list(,$power) = $info;
echo "I need $power!\n"; ?>

PHP手册
用法

原文链接:https://www.f2er.com/php/26646.html

猜你在找的PHP相关文章