函数count()
描述:
计算一变量中元素的个数
intcount(mixedvar);
Returnsthenumberofelementsinvar,whichistypicallyanarray(sinceanythingelsewillhaveoneelement).
Returns0ifthevariableisnotset.
Returns1ifthevariableisnotanarray.
函数current()
描述:
传回数组指针目前所指的元素
mixedcurrent(arrayarray);
Eacharrayvariablehasaninternalpointerthatpointstooneofitselements.Inaddition,alloftheelementsinthearrayarelinkedbyabidirectionallinkedlistfortraversingpurposes.Theinternalpointerpointstothefirstelementthatwasinsertedtothearrayuntilyourunoneofthefunctionsthatmodifythatpointeronthatarray.
Thecurrent()functionsimplyreturnsthearrayelementthat'scurrentlybeingpointedbytheinternalpointer.Itdoesnotmovethepointerinanyway.Iftheinternalpointerpointsbeyondtheendoftheelementslist,current()returnsfalse.
函数each()
描述:
返回数组中下一对key/value的值
arrayeach(arrayarray);
Returnsthecurrentkey/valuepairfromthearrayarrayandadvancesthearraycursor.Thispairisreturnedinafour-elementarray,withthekeys0,1,key,andvalue.Elements0andkeyeachcontainthekeynameofthearrayelement,and1andvaluecontainthedata.
Example1.each()examples
$foo=array("bob","fred","jussi","jouni");$bar=each($foo);
$barnowcontainsthefollowingkey/valuepairs:
0=>0
1=>'bob'
key=>0
value=>'bob'
$foo=array("Robert"=>"Bob","Seppo"=>"Sepi");$bar=each($foo);
$barnowcontainsthefollowingkey/valuepairs:
0=>'Robert'
1=>'Bob'
key=>'Robert'
value=>'Bob'
Example2.Traversing$HTTP_POST_VARSwitheach()
echo"ValuessubmittedviaPOSTmethod:<br>";
while(list($key,$val)=each($HTTP_POST_VARS)){
echo"$key=>$val<br>";
}
函数end()
描述:
将数组中的指针移到最后一个
end(arrayarray);
end()advancesarray'sinternalpointertothelastelement.
函数key()
描述:
从一数组中取出key
mixedkey(arrayarray);
key()returnstheindexelementofthecurrentarrayposition.
函数ksort()
描述:
以key来排列一数组
Example1.ksort()example
$fruits=array("d"=>"lemon","a"=>"orange","b"=>"banana","c"=>"apple");
ksort($fruits);
for(reset($fruits);
$key=key($fruits);
next($fruits)){echo"fruits[$key]=".$fruits[$key]."
";}
Thisexamplewoulddisplay:fruits[a]=orangefruits[b]=bananafruits[c]=applefruits[d]=lemon
函数list()
描述:
用类似数组的方式去指定一整串变量的值
Example1.list()example
<table><tr><th>Employeename</th>
<th>Salary</th></tr>
<?php$result=
mysql($conn,"SELECTid,name,salaryFROMemployees");
while(list($id,$name,$salary)=
mysql_fetch_row($result)){
print("<tr>
"."<td><ahref="info.php3?id=$id">$name</a></td>
"."<td>$salary</td>
"."</tr>
");
}
?>
</table>
函数next()
描述:
将数组的指向指到下一组数据
函数pos()
描述:
传回数组的当前的数据
函数prev()
描述:
传回数组的前一条的数据
函数reset()
描述:
数组的指针指到第一条
函数rsort()
描述:
以倒序方式排列一个数组
Example1.rsort()example
$fruits=array("lemon","orange","banana","apple");
rsort($fruits);
for(reset($fruits);($key,$value)=each($fruits);){
echo"fruits[$key]=".$value."
";
}
Thisexamplewoulddisplay:fruits[0]=orangefruits[1]=lemonfruits[2]=bananafruits[3]=appleThefruitshavebeensortedinreversealphabeticalorder.
函数sizeof()
描述:
取得一个数组的大小和元素的数目
函数sort()
描述:
排序数组
Example1.sort()example
$fruits=array("lemon","orange","banana","apple");
sort($fruits);
for(reset($fruits);
$key=key($fruits);
next($fruits)){
echo"fruits[$key]=".$fruits[$key]."
";
}
Thisexamplewoulddisplay:fruits[0]=applefruits[1]=bananafruits[2]=lemonfruits[3]=orangeThefruitshavebeensortedinalphabeticalorder.