Êý×é´¦Àíº¯Êý¿âµÚ1/2Ò³

5年以前  |  阅读数:237 次  |  编程语言:PHP 

array : ½¨Á¢Ò»¸oеÄÊý×e¡£

array_walk : ÈÃÓû§×Ô¶(C)º¯ÊýÄÜ´¦ÀiÊý×eÖеÄÿһ¸oÔªËØ¡£

arsort : ½«Êý×eµÄÖµÓÉ´oµ½Ð¡ÅÅÐo¡£

asort : ½«Êý×eµÄÖµÓÉСµ½´oÅÅÐo¡£

count : ¼ÆËa±aÁ¿»oÊý×eÖеÄÔªËظoÊý¡£

current : *µ»ØÊý×eÖÐÄ¿Ç°µÄÔªËØ¡£

each : *µ»ØÊý×eÖÐÏÂÒ»¸oÔªËصÄË÷Òý¼°Öµ¡£

end : ½«Êý×eµÄÄÚ²¿Ö¸ÕeÖ¸µ½×iºoµÄÔªËØ¡£

key : È¡µÃÊý×eÖеÄË÷Òý×ÊÁÏ¡£

ksort : ½«Êý×eµÄÔªËØÒÀË÷ÒýÅÅÐo¡£

list : ÁгoÊý×eÖÐÔªËصÄÖµ¡£

next : ½«Êý×eµÄÄÚ²¿Ö¸ÕeÏoºoÒƶ¯¡£

pos : *µ»ØÊý×eÄ¿Ç°µÄÔªËØ¡£

prev : ½«Êý×eµÄÄÚ²¿Ö¸ÕeÍuÇ°Òƶ¯¡£

range : ½¨Á¢Ò»¸oÕuÊý*¶Î§µÄÊý×e¡£

reset : ½«Êý×eµÄÖ¸ÕeÖ¸µ½Êý×eµÚÒ»¸oÔªËØ¡£

rsort : ½«Êý×eµÄÖµÓÉ´oµ½Ð¡ÅÅÐo¡£

shuffle : ½«Êý×eµÄ˳ÐoŪ»i¡£

sizeof : »ñÖªÊý×eµÄ´oС¡£

sort : ½«Êý×eÅÅÐo¡£

uasort : ½«Êý×eÒÀÓû§×Ô¶¨µÄº¯ÊýÅÅÐo¡£

uksort : ½«Êý×eµÄË÷ÒýÒÀÓû§×Ô¶¨µÄº¯ÊýÅÅÐo¡£

usort : ½«Êý×eµÄÖµÒÀÓû§×Ô¶¨µÄº¯ÊýÅÅÐo¡£

array

½¨Á¢Ò»¸oеÄÊý×e¡£

Ói*¨: array array(...);

*µ»ØÖµ:Êý×e

º¯ÊýÖÖÀa: ×ÊÁÏ´¦Ài

ÄÚÈÝ˵Ã÷: *µ»ØµÄ²ÎÊýÊÇÊý×eÀaÐÍ¡£²ÎÊý¿ÉÒÔÊÇ´øÓÐ => ÔËËa×ÓµÄË÷Òý¡£array() Æaʵ²»ÊÇÒ»¸oÕý¹aeµÄº¯Êý£¬ËuÖ÷ÒªÊÇÒªÓÃÀ´±iʾÊý×e¡£

ʹÓöÀý : ÏÂÃae¶ÀýÓÃÏÔʾÈçºÎ½¨Á¢Ò»¸o¶þάÊý×e£¬ÈçºÎÖ¸¶¨ÁªºÏÊý×eµÄ¼uÖµ£¬¼°ÈçºÎÂÔ¹ýºÍ¼ÌÐøÊý×eÖеÄÊý×ÖË÷Òý¡£

$fruits = array(
"fruits" => array("a"=>"orange","b"=>"banana","c"=>"apple"),
"numbers" => array(1, 2, 3, 4, 5, 6),
"holes" => array("first", 5 => "second", "third")
);

²Î¿¼ list()

array_walk
ÈÃʹÓÃÕß×Ô¶(C)º¯ÊýÄÜ´¦ÀiÊý×eÖеÄÿһ¸oÔªËØ¡£

Ói*¨: int array_walk(array arr, string func);

*µ»ØÖµ: ÕuÊý

º¯ÊýÖÖÀa: ×ÊÁÏ´¦Ài

ÄÚÈÝ˵Ã÷ ´Ëº¯Êýʹÿ¸oÊý×eÔªËØ arr ÒÀÐoÓeº¯ÊýÃu³Æ func Ïa¶ÔÓ¦¡£ÔªËØ´«Ë͵½º¯Êý func µÄµÚÒ»¸o²ÎÊý£¬Èo²ÎÊý³¬¹ýÒ»¸o£¬Ôoÿ´Î¶¼»aÓо¯¸aeÐÅÏ¢¡£Òª´¦Ài¾¯¸aeÐÅÏ¢£¬¿ÉÔÚ±¾º¯ÊýÇ°Ãae¼ÓÉÏ '@' ×Ö*u (±a³É @array_walk)£»»oÊÇʹÓà error_reporting º¯Êý¡£

×¢Òa: ʹÓÃÕß×Ô¶(C)º¯Êý func ÕaeµÄ»a½«Êý×eÔªËØ arr ÒÀÐo´uÈe£¬ËuÒÔÈκζÔÔªËØËu×oµÄ¸Ä±a¶¼»aÓ°Ïiµ½Êý×e±¾Éi¡£

ʹÓÃ*¶Àý

<?
$fruits = array("d"=>"lemon","a"=>"orange","b"=>"banana","c"=>"apple");
function test_alter( $item1 ) {
$item1 = 'bogus';
}function test_print( $item2 ) {
echo "$item2
n";
}array_walk( $fruits, 'test_print' );
array_walk( $fruits, 'test_alter' );
array_walk( $fruits, 'test_print' );
?>
²Î¿¼ each() list()

arsort
½«Êý×eµÄÖµÓÉ´oµ½Ð¡ÅÅÐo¡£
Ói¨: void arsort(array array);
µ»ØÖµ: ÎÞ
º¯ÊýÖÖÀa:×ÊÁÏ´¦ÀiÄÚÈÝ˵Ã÷Õa¸oº¯Êý½«Êý×eµÄÖµÖØÐÂÅÅÐo£¬ÓÉ´oÖÁСÅÅÁС£Êý×eµÄË÷ÒýÒa¸u×ÅÖµµÄþÄ˳Ðo¶ø±a¶¯¡£µ±ÄuÔÚ³ÌÐoÖÐÐeÒªÖØÐÂÕuÀiÊý×eÖµµÄþÄ˳Ðoʱ£¬¾Í¿ÉÒÔʹÓÃÕa¸oº¯Êý¡£

ʹÓöÀý
µ×ϵÄ
¶Àý*µ»ØµÄ½a¹uΪ
fruits[a] = orange
fruits[d] = lemon
fruits[b] = banana
fruits[c] = apple¡£
ÎÒÃÇ¿ÉÒÔ¿´µ½Ë®¹uÃu (Êý×eÖµ) ÒÑ°´Ó¢ÎÄ×ÖĸµÄ˳ÐoÓÉ z Íu a ÖØÐÂÅÅÐo£¬¶øË÷ÒýÒa¸u×ÅÖµ±a¶¯¡£
<?
$fruits = array("d"=>"lemon","a"=>"orange","b"=>"banana","c"=>"apple");
arsort($fruits);
for(reset($fruits); $key = key($fruits); next($fruits)) {
echo "fruits[$key] = ".$fruits[$key]."n";
}
?>

²Î¿¼ asort() rsort() ksort() sort()

asort
½«Êý×eµÄÖµÓÉСµ½´oÅÅÐo¡£
Ói¨: void asort(array array);
µ»ØÖµ: ÎÞ
º¯ÊýÖÖÀa: ×ÊÁÏ´¦Ài

ÄÚÈÝ˵Ã÷ Õa¸oº¯Êý½«Êý×eµÄÖµÖØÐÂÅÅÐo£¬ÓÉСÖÁ´oÅÅÁС£Êý×eµÄË÷ÒýÒa¸u×ÅÖµµÄþÄ˳Ðo¶ø±a¶¯¡£µ±ÄuÔÚ³ÌÐoÖÐÐeÒªÖØÐÂÕuÀiÊý×eÖµµÄþÄ˳Ðoʱ£¬¾Í¿ÉÒÔʹÓÃÕa¸oº¯Êý¡£

ʹÓöÀý
µ×ϵÄ
¶Àý*µ»ØµÄ½a¹uΪ
fruits[c] = apple
fruits[b] = banana
fruits[d] = lemon
fruits[a] = orange
ÎÒÃÇ¿ÉÒÔ¿´µ½Ë®¹uÃu (Êý×eÖµ) ÒÑ°´Ó¢
ÎÄ×ÖĸµÄ˳ÐoÓÉ a Íu z ÅÅÐo£¬¶øË÷ÒýÒa¸u×ÅÖµ±a¶¯¡£
<?
$fruits = array("d"=>"lemon","a"=>"orange","b"=>"banana","c"=>"apple");
asort($fruits);
for(reset($fruits); $key = key($fruits); next($fruits)) {
echo "fruits[$key] = ".$fruits[$key]."n";
}
?>

²Î¿¼ arsort() rsort() ksort() sort()

count
¼ÆËa±aÁ¿»oÊý×eÖеÄÔªËظoÊý¡£
Ói¨: int count(mixed var);
µ»ØÖµ: ÕuÊý
º¯ÊýÖÖÀa: ×ÊÁÏ´¦Ài

ÄÚÈÝ˵Ã÷ Õa¸oº¯ÊýÓÃÀ´¼ÆËaÊý×eµÄÔªËظoÊý (Òa¿É½«±aÁ¿´uÈe£¬Ö»²»¹ýµ»ØµÄÕuÊý½«ÊÇ 1)¡£±aÁ¿»¹Ã»ÓÐÅaÖÃʱ£¬µ»ØֵΪ 0¡£±aÁ¿Èo²»ÊÇÊý×e£¬*µ»ØֵΪ 1¡£

²Î¿¼ sizeof() isset() is_array()

current
µ»ØÊý×eÖÐÄ¿Ç°µÄÔªËØ¡£
Ói
¨: mixed current(array array);
*µ»ØÖµ: »iºÏÀaÐÍ×ÊÁÏ
º¯ÊýÖÖÀa: ×ÊÁÏ´¦Ài

ÄÚÈÝ˵Ã÷ ˵Ã÷: ÿһ¸oÊý×e±aÁ¿¶¼ÓÐÒ»¸oÄÚ²¿Ö¸Õe£¬Ö¸µ½ËuµÄÿһ¸oÔªËØ¡£´ËÍa£¬ÎªÁ˽»»¥²Î¿¼£¬Êý×eÓÐÝËuÓÐÔªËصÄË«ÏoÁ´½a±i¡£Êý×eµÄÄÚ²¿Ö¸ÕeÖ¸µ½Ô­ÏȲaÈeµÄÔªËØÉÏ£¬Ö±µ½³ÌÐoÖ´Ðе½ÓиĶ¯Êý×eÖ¸ÕeµÄº¯Êý¡£º¯Êý current() ¼oµ¥µØµ»ØÊý×eÔªËØÖÐÄ¿Ç°Ö¸µ½µÄÊý×eÄÚ²¿Ö¸Õe¡£Ëu²»»a¸Ä±aÖ¸ÕeµÄÖµ£¬ÈoÊý×eÖ¸ÕeÖ¸µ½ÄÚ²¿Ö¸Õe±iÍa£¬Ôo*µ»Ø false µÄÖµ¡£

×¢Òa: ÈoÊý×eÖаuº¬¿ÕµÄÔªËØ (0 »oÕß "" ¿Õ×Öu´®)£¬Ôo±¾º¯Êý»aµ»Ø false Öµ¡£ÒªÊÇÄ¿Ç°ÔªËØÊǸoÁaÖµµÄþÄ¿ÕÔªËØ»oÕßÊdz¬³oÊý×eÖ¸Õe£¬½a¹uµ±È»ÊÇ䶨µÄ false Öµ¡£Óoµ½ÕaÖÖÇeÐΣ¬¿ÉÒÔʹÓà each() º¯Êý»a¸uÊʺϡ£

²Î¿¼ end() next() prev() reset()

each
µ»ØÊý×eÖÐÏÂÒ»¸oÔªËصÄË÷Òý¼°Öµ¡£
Ói
¨: array each(array array);
*µ»ØÖµ: Êý×e
º¯ÊýÖÖÀa: ×ÊÁÏ´¦Ài

ÄÚÈÝ˵Ã÷ µ»ØÊý×eΪĿǰÊý×eÖ¸ÕeµÄ Ë÷Òý/Öµ ¶Ô¡£µ»ØµÄÊý×eÓÐËĸoÔªËØ£¬ÒÀÐoΪ 0, 1, Ë÷Òý, ¼°Öµ¡£Ç°ÊoµÄ 0 Óe Ë÷Òý ΪÊý×eµÄË÷Òý£¬1 Óe ÖµÔoΪÊý×eÔªËصÄÖµ¡£
ʹÓöÀý
¶ÀýÒ»:
<?
$foo = array( "bob", "fred", "jussi", "jouni" );
$bar = each( $foo );
?>
ÉÏÃaeµÄÀý×Ó£¬*µ»ØÊý×e $bar µÄ Ë÷Òý/Öµ Ϊ
0 => 0
1 => 'bob'
key => 0
value => 'bob'

¶Àý¶þ:
<?
$foo = array( "Robert" => "Bob", "Seppo" => "Sepi" );
$bar = each( $foo );
?>
Õa¸oµÄÀý×Ó£¬
µ»ØÊý×e $bar µÄ Ë÷Òý/Öµ Ϊ
0 => 'Robert'
1 => 'Bob'
key => 'Robert'
value => 'Bob'

*¶ÀýÈý:
each() º¯Êý×iµaÐ͵ÄÀý×ÓÊÇÄÃÀ´Óe list() º¯ÊýºÏÓã¬ÈçÏÂÀýµÄ $HTTP_POST_VARS ±aÁ¿¡£
<?
echo "POST ËuËͳoµÄֵΪ:
";
while ( list( $key, $val ) = each( $HTTP_POST_VARS ) ) {
echo "$key => $val
";
}
?>

²Î¿¼ current() key() list() next() prev() reset()

end
½«Êý×eµÄÄÚ²¿Ö¸ÕeÖ¸µ½×iºoµÄÔªËØ¡£
Ói¨: end(array array);
µ»ØÖµ: ÎÞ
º¯ÊýÖÖÀa: ×ÊÁÏ´¦Ài

ÄÚÈÝ˵Ã÷ ±¾º¯Êý»a¸Ä±aÊý×eµÄÄÚ²¿Ö¸Õe£¬Ëu½«Ö¸ÕeÖ¸µ½×iºoÒ»¸oÔªËØÉÏ¡£

²Î¿¼ current() each() next() reset()

key
È¡µÃÊý×eÖеÄË÷Òý×ÊÁÏ¡£
Ói¨: mixed key(array array);
µ»ØÖµ: »iºÏÀaÐÍ×ÊÁÏ
º¯ÊýÖÖÀa: ×ÊÁÏ´¦Ài
ÄÚÈÝ˵Ã÷
±¾º¯Êý´ÓÄ¿Ç°Êý×eµÄÖ¸Õe£¬*µ»ØÆaË÷Òý

²Î¿¼ current() next()

ksort
½«Êý×eµÄÔªËØÒÀË÷ÒýÅÅÐo¡£
Ói¨: void ksort(array array);
µ»ØÖµ: ÎÞ
º¯ÊýÖÖÀa: ×ÊÁÏ´¦Ài
ÄÚÈÝ˵Ã÷
±¾º¯Êý½«Êý×eÖеÄÔªËØÒÀË÷ÒýÅÅÐo£¬ÅÅÐoºoµÄË÷ÒýºÍÖµÈÔÈ»¶ÔÓ¦

µ±Ç°1/2Ò³ 12ÏÂÒ»Ò³ÔĶÁÈ«ÎÄ

 相关文章:
PHP分页显示制作详细讲解
SSH 登录失败:Host key verification failed
获取IMSI
将二进制数据转为16进制以便显示
获取IMEI
文件下载
贪吃蛇
双位运算符
PHP自定义函数获取搜索引擎来源关键字的方法
Java生成UUID
发送邮件
年的日历图
提取后缀名
在Zeus Web Server中安装PHP语言支持
让你成为最历害的git提交人
Yii2汉字转拼音类的实例代码
再谈PHP中单双引号的区别详解
指定应用ID以获取对应的应用名称
Python 2与Python 3版本和编码的对比
php封装的page分页类完整实例