PHPѧϰ(15) Êý×éµÄ±éÀúºÍÅÅÐò
PHPÖУ¬Êý×é×î¼òµ¥µÄ±éÀú·½·¨Äª¹ýÓÚforºÍforeachÁË¡£ÆäÖÐforeachÓÐÁ½ÖÖд·¨£¬Ò»ÖÖÖ»±éÀúÖµ¡¢ÁíÒ»ÖÖ±éÀúË÷ÒýºÍÖµ¡£¾ßÌå¿ÉÒÔ¿´ÈçÏ´úÂë¡£
$test01 = array('a', 'b', 'c'); // for for ($i = 0; $i < count($test01); $i++) { echo $test01[$i]; } // foreach value only foreach ($test01 as $value) { echo $value; } // foreach key and value $test01 = array('a' => 'aaaa', 'b' => 'bbbb', 'c' => 'cccc'); foreach ($test01 as $key => $value) { echo "$key => $value"; }2.µü´úÆ÷±éÀú
PHPÖУ¬µü´ú±éÀúÖ÷ÒªÒªÓõ½ÒÔϺ¯Êý¡£
current() µü´úµÄµ±Ç°ÔªËØ¡£
reset() ÖØÐÂÒƶ¯µ½µÚÒ»¸öÔªËز¢·µ»ØËü¡£
next() Òƶ¯µ½ÏÂÒ»¸öÔªËز¢·µ»ØËü¡£
prev() Òƶ¯µ½ÉÏÒ»¸öÔªËز¢·µ»ØËü¡£
end() Òƶ¯µ½×îºóÒ»¸öÔªËز¢·µ»ØËü¡£
each() ÒÔÊý×éµÄÐÎʽ·µ»Øµ±Ç°ÔªËصÄË÷ÒýºÍÖµ£¬²¢Òƶ¯µ½ÏÂÒ»¸öµü´ú¡£
key() ·µ»Øµ±Ç°µÄË÷Òý¡£
array_ walk() Ϊÿһ¸öÔªËص÷Óú¯Êý¡£
array_ reduce() Ϊÿһ¸öÔªËØÒÀ´Î¼ÆËã¡£
$test01 = array('a' => 'aaaa', 'b' => 'bbbb', 'c' => 'cccc'); while (list($key, $value) = each($test01)) { echo "$key => $value" . "<br/>"; } array_walk($test01, walk_test); function walk_test($key, $value) { echo "walk: $key => $value" . "<br/>"; } $test02 = array(1, 2, 3, 4, 5); echo array_reduce($test02, reduce_test); function reduce_test($run_result, $current_value) { return $run_result + $current_value * $current_value; }3.Êý×éµÄÅÅÐò
ÔÚPHPÖУ¬ÅÅÐò·½Ê½ÓÐÈýÖÖ£¬Í¨¹ýË÷ÒýÅÅÐò¡¢Í¨¹ýÖµÅÅÐò£¨²»±£ÁôÔË÷Òý£©¡¢Í¨¹ýÖµÅÅÐò£¨±£ÁôÔË÷Òý£©¡£Ã¿ÖÖÓÖ·ÖΪÉýÐò¡¢½µÐòÒÔ¼°Óû§¶¨Òå˳ÐòÈý¸öº¯Êý¡£ËüÃÇ·Ö±ðÈçÏ£º
ͨ¹ýË÷ÒýÅÅÐò£º¢ÙÉýÐò ksort()¡¡¢Ú½µÐò krsort()¡¡¢ÛÓû§¶¨Òå˳Ðò uksort()
²»±£ÁôÔË÷ÒýÖµÅÅÐò£º¢ÙÉýÐò sort()¡¡¢Ú½µÐò rsort()¡¡¢ÛÓû§¶¨Òå˳Ðò usort()
±£ÁôÔË÷ÒýÖµÅÅÐò£º¢ÙÉýÐò asort()¡¡¢Ú½µÐò arsort()¡¡¢ÛÓû§¶¨Òå˳Ðò uasort()
ÔÚPHPÖУ¬Ò²¿ÉÒÔÓÃarray_multisortÀ´Ò»´ÎÅÅÐò¶à¸öÊý×飬²»¹ýÏîÄ¿ÖпÉÄÜÓõñȽÏÉÙ¡£
·×ªÊý×飬°ÑÊý×ÖË÷Òý·×ª£¬Ë÷ÒýÖØдÓ0¿ªÊ¼£ºarray_reverse()
°ÑË÷ÒýºÍÖµµ÷»»£ºarray_flip()
Ëæ»ú˳Ðò£ºshuffle()
ÒòΪÉÏÃæµÄº¯Êý¹Ù·½µÄÀý×Ó¶¼ºÜÈÝÒ׶®£¬¾Íûд´úÂëÁË¡£
ÍƼöÐÅÏ¢
- ¡¾ÊÓƵ²¥·Å¡¿JplayerÊÓƵ²¥·ÅÆ÷µÄʹÓÃ
- memcacheÄÚ´æÔÀí
- Memcache¼¼Êõ·ÖÏí£º½éÉÜ¡¢Ê¹Óᢴ洢¡¢Ëã·¨¡¢ÓÅ»¯....
- php³£ÓÃÕýÔò±í´ïʽ
- phpÐÔÄܼà²âÄ£¿éXHProf
- ÈÃCI¿ò¼ÜÖ§³Öservice²ã
- ʹÓÃPHPÉú³É´øLOGOµÄ¸öÐÔ»¯¶þάÂëͼÏñ
- ¹ØÓÚCodeIgniterÄã¿ÉÄܲ»ÖªµÀµÄ5¸ö֪ʶµã
- Memcache ºÁÃ뼶³¬Ê±¼°ÆäËû³£¼ûÎÊÌâ»ã×Ü
- [PHP±Ê¼Ç]PHPQueryÒ»¸ö´¦ÀíDOMµÄÀûÆ÷
ÈÈÃÅÐÅÏ¢
- nohup: redirecting stderr to stdou....
- ʹÓÃlog_formatΪNginx·þÎñÆ÷ÉèÖøüÏêϸµÄÈÕÖ¾¸ñʽ
- jquery easyUI--dataGrid-Json
- [Ô´´]·ÂGoogle Reader¡¢ÐÂÀË΢²©¡¢ÌÚѶ΢²©µ....
- ÀûÓÃKeepalived+mysql¹¹½¨¸ß¿ÉÓÃMySQLË«Ö÷×Ô¶....
- Nginx+keepalivedʵÏÖ¸ºÔؾùºâºÍË«»úÈȱ¸¸ß¿ÉÓÃ
- jqueryʵÏÖÒ³Ãæ¼ÓÔؽø¶ÈÌõ
- Rolling cURL: PHP²¢·¢×î¼Ñʵ¼ù
- codeigniter ·ÓÉÖÕ¼«ÓÅ»¯(url rewrite)
- linuxÏÂÉèÖÃsshÎÞÃÜÂëµÇ¼
×î½ü¸üÐÂ
- PHP»ñÈ¡Óû§µÄÕæʵIP£¬²¢ÅжÏÊÇ·ñÄÚÍøIP
- PHP ´íÎóÈÕÖ¾ error_log
- ÀûÓÃbigpipe»úÖÆʵÏÖÒ³ÃæÄ£¿éµÄÒì²½äÖȾ chunked¼¼Êõ
- php¿ØÖÆÎļþÏÂÔØËÙ¶È
- js + php ¶ÁÈ¡¡¢²¥·ÅÊÓƵÁ÷ ¼æÈÝfirefox£¬c....
- ¡¾ÊÓƵ²¥·Å¡¿JplayerÊÓƵ²¥·ÅÆ÷µÄʹÓÃ
- UNICODE Óë UTF-8 µÄ¹Øϵ
- memcacheÄÚ´æÔÀí
- Memcache¼¼Êõ·ÖÏí£º½éÉÜ¡¢Ê¹Óᢴ洢¡¢Ëã·¨¡¢ÓÅ»¯....
- phpʹÓÃmb_detect_encoding¼ì²â×Ö·û´®±àÂë
ÆÀÂÛ