PHPº¯ÊýµÄʵÏÖÔÀí¼°ÐÔÄÜ·ÖÎö(2)
½á¹û·ÖÎö
ÄÚÖú¯ÊýºÍCº¯ÊýµÄ¿ªÏúÔÚÈ¥µôphpº¯Êý¿Õµ÷ÓõÄÓ°Ïìºó²î¾à½ÏС£¬Ëæן¯Êý¹¦ÄÜÔ½À´Ô½¸´ÔÓ£¬Ë«·½ÐÔÄÜÇ÷½üÓÚÏàͬ¡£Õâ¸ö´Ó֮ǰµÄº¯ÊýʵÏÖ·ÖÎöÖÐÒ²ÈÝÒ׵õ½ÂÛÖ¤£¬±Ï¾¹ÄÚÖú¯Êý¾ÍÊÇCʵÏֵġ£
º¯Êý¹¦ÄÜÔ½¸´ÔÓ£¬cºÍphpµÄÐÔÄܲî¾àԽС
Ïà¶ÔcÀ´Ëµ£¬phpº¯Êýµ÷ÓõĿªÏú´óºÜ¶à£¬¶ÔÓÚ¼òµ¥º¯ÊýÀ´ËµÐÔÄÜ»¹ÊÇÓÐÒ»¶¨Ó°Ïì¡£Òò´ËphpÖк¯Êý²»ÒËǶÌ×·â×°Ì«Éî¡£
αº¯Êý¼°ÆäÐÔÄÜ
ÔÚphpÖУ¬ÓÐÕâÑùһЩº¯Êý£¬ËüÃÇÔÚʹÓÃÉÏÊDZê×¼µÄº¯ÊýÓ÷¨£¬µ«µ×²ãʵÏÖÈ´ºÍÕæÕýº¯Êýµ÷ÓÃÍêÈ«²»Í¬£¬ÕâЩº¯Êý²»ÊôÓÚÇ°ÎÄÌáµ½µÄÈýÖÖfunctionÖеÄÈκÎÒ»À࣬ÆäʵÖÊÊÇÒ»Ìõµ¥¶ÀµÄopcode£¬ÕâÀï¹ÀÇÒ½Ð×öαº¯Êý»òÕßÖ¸ÁÊý¡£
ÈçÉÏËù˵£¬Î±º¯ÊýʹÓÃÆðÀ´ºÍ±ê×¼µÄº¯Êý²¢ÎÞ¶þÖ£¬¿´ÆðÀ´¾ßÓÐÏàͬµÄÌØÕ÷¡£µ«ÊÇËûÃÇ×îÖÕÖ´ÐеÄʱºòÊDZ»zend·´Ó³³ÉÁËÒ»Ìõ¶ÔÓ¦µÄÖ¸Áopcode£©À´µ÷Óã¬Òò´ËÆäʵÏÖ¸ü½Ó½üÓÚif¡¢for¡¢ËãÊõÔËËãµÈ²Ù×÷¡£
phpÖеÄαº¯Êý
isset
empty
unset
eval
ͨ¹ýÉÏÃæµÄ½éÉÜ¿ÉÒÔ¿´³ö£¬Î±º¯ÊýÓÉÓÚ±»Ö±½Ó·Òë³ÉÖ¸ÁîÀ´Ö´ÐУ¬ºÍÆÕͨº¯ÊýÏà±ÈÉÙÁËÒ»´Îº¯Êýµ÷ÓÃËù´øÀ´µÄ¿ªÏú£¬Òò´ËÐÔÄÜ»á¸üºÃһЩ¡£ÎÒÃÇͨ¹ýÈçϲâÊÔÀ´×öÒ»¸ö¶Ô±È¡£ Array_key_existsºÍissetÁ½Õ߶¼¿ÉÒÔÅжÏÊý×éÖÐij¸ökeyÊÇ·ñ´æÔÚ£¬¿´Ò»ÏÂËûÃǵÄÐÔÄÜ
´ÓͼÉÏ¿ÉÒÔ¿´³ö£¬ºÍarray_key_existsÏà±È£¬issetÐÔÄÜÒª¸ß³öºÜ¶à£¬»ù±¾ÊÇÇ°ÕßµÄ4±¶×óÓÒ£¬¶ø¼´Ê¹ÊǺͿպ¯Êýµ÷ÓÃÏà±È£¬ÆäÐÔÄÜÒ²Òª¸ß³ö1±¶×óÓÒ¡£ÓÉ´ËÒ²²àÃæÓ¡Ö¤ÔÙ´Î˵Ã÷ÁËphpº¯Êýµ÷ÓõĿªÏú»¹ÊDZȽϴóµÄ¡£
³£ÓÃphpº¯ÊýʵÏÖ¼°½éÉÜ
count
countÊÇÎÒÃǾ³£Óõ½µÄÒ»¸öº¯Êý£¬Æ书ÄÜÊÇ·µ»ØÒ»¸öÊý×éµÄ³¤¶È¡£
countÕâ¸öº¯Êý£¬Æ临ÔÓ¶ÈÊǶàÉÙÄØ£¿
Ò»ÖÖ³£¼ûµÄ˵·¨ÊÇcountº¯Êý»á±éÀúÕû¸öÊý×éÈ»ºóÇó³öÔªËظöÊý£¬Òò´Ë¸´ÔÓ¶ÈÊÇO(n)¡£ÄÇʵ¼ÊÇé¿öÊDz»ÊÇÕâÑùÄØ£¿
ÎÒ
Ãǻص½countµÄʵÏÖÀ´¿´Ò»Ï£¬Í¨¹ýÔ´Âë¿ÉÒÔ·¢ÏÖ£¬¶ÔÓÚÊý×éµÄcount²Ù×÷£¬º¯Êý×îÖյķ¾¶ÊÇzif_count->
php_count_recursive->
zend_hash_num_elements£¬¶øzend_hash_num_elementsµÄÐÐΪÊÇ return
ht->nNumOfElements£¬¿É¼û£¬ÕâÊÇÒ»¸öO(1)¶ø²»ÊÇO(n)µÄ²Ù×÷¡£Êµ¼ÊÉÏ£¬Êý×éÔÚphpµ×²ã¾ÍÊÇÒ»¸öhash_table£¬¶Ô
ÓÚhash±í£¬zendÖÐרÃÅÓÐÒ»¸öÔªËØnNumOfElements¼Ç¼Á˵±Ç°ÔªËصĸöÊý£¬Òò´Ë¶ÔÓÚÒ»°ãµÄcountʵ¼ÊÉÏÖ±½Ó¾Í·µ»ØÁËÕâ¸öÖµ¡£ÓÉ´Ë£¬
ÎÒÃǵóö½áÂÛ£º countÊÇO(1)µÄ¸´ÔӶȣ¬ºÍ¾ßÌåÊý×éµÄ´óСÎ޹ء£
·ÇÊý×éÀàÐ͵ıäÁ¿£¬countµÄÐÐΪʱÔõÑù£¿
¶ÔÓÚδÉèÖñäÁ¿·µ»Ø0£¬¶øÏñint¡¢double¡¢stringµÈÔò»á·µ»Ø1
strlen
StrlenÓÃÓÚ·µ»ØÒ»¸ö×Ö·û´®µÄ³¤¶È¡£ÄÇô£¬ËûµÄʵÏÖÔÀíÊÇÈçºÎµÄÄØ£¿
ÎÒÃǶ¼ÖªµÀÔÚcÖÐstrlenÊÇÒ»¸ö
o(n)µÄº¯Êý£¬»á˳Ðò±éÀú×Ö·û´®Ö±µ½Óöµ½\0£¬È»ºó³ö³¤¶È¡£PhpÖÐÊÇ·ñÒ²ÕâÑùÄØ£¿´ð°¸ÊÇ·ñ¶¨µÄ£¬phpÀï×Ö·û´®ÊÇÓÃÒ»¸ö¸´ºÏ½á¹¹À´ÃèÊö£¬°üÀ¨Ö¸Ïò¾ßÌå
Êý¾ÝµÄÖ¸ÕëºÍ×Ö·û´®³¤¶È£¨ºÍc++ÖÐstringÀàËÆ£©£¬Òò´Ëstrlen¾ÍÖ±½Ó·µ»Ø×Ö·û´®³¤¶ÈÁË£¬Êdz£Êý¼¶±ðµÄ²Ù×÷¡£
ÁíÍ⣬¶ÔÓÚ·Ç×Ö·û´®ÀàÐ͵ıäÁ¿µ÷ÓÃstrlen£¬Ëü»áÊ×ÏȽ«±äÁ¿Ç¿ÖÆת»»Îª×Ö·û´®ÔÙÇ󳤶ȣ¬ÕâµãÐèҪעÒâ¡£
issetºÍarray_key_exists
ÕâÁ½¸öº¯Êý×î³£¼ûµÄÓ÷¨¶¼ÊÇÅжÏÒ»¸ökeyÊÇ·ñÔÚÊý×éÖдæÔÚ¡£µ«ÊÇÇ°Õß»¹¿ÉÒÔÓÃÓÚÅжÏÒ»¸ö±äÁ¿ÊÇ·ñ±»ÉèÖùý¡£
ÈçÇ°ÎÄËùÊö£¬isset²¢·ÇÕæÕýµÄº¯Êý£¬Òò´ËËüµÄЧÂÊ»á±ÈºóÕ߸ߺܶࡣÍƼöÓÃËü´úÌæarray_key_exists¡£
array_pushºÍarray[]
Á½Õ߶¼ÊÇÍùÊý×éβ²¿×·¼ÓÒ»¸öÔªËØ¡£²»Í¬µÄÊÇÇ°Õß¿ÉÒÔÒ»´Îpush¶à¸ö¡£ËûÃÇ×î´óµÄÇø±ðÔÚÓÚÒ»¸öÊǺ¯ÊýÒ»¸öÊÇÓïÑԽṹ£¬Òò´ËºóÕßЧÂÊÒª¸ü¸ß¡£Òò´ËÈç¹ûÖ»ÊÇÆÕͨµÄ×·¼ÓÔªËØ£¬½¨ÒéʹÓÃarray []¡£
randºÍmt_rand
Á½Õ߶¼ÊÇÌṩ²úÉúËæ»úÊýµÄ¹¦ÄÜ£¬Ç°ÕßʹÓÃlibc±ê×¼µÄrand¡£ºóÕßÓÃÁË Mersenne Twister
ÖÐÒÑÖªµÄÌØÐÔ×÷ΪËæ»úÊý·¢ÉúÆ÷£¬Ëü¿ÉÒÔ²úÉúËæ»úÊýÖµµÄƽ¾ùËÙ¶È±È libc ÌṩµÄ rand()
¿ìËı¶¡£Òò´ËÈç¹û¶ÔÐÔÄÜÒªÇó½Ï¸ß£¬¿ÉÒÔ¿¼ÂÇÓÃmt_rand´úÌæÇ°Õß¡£
ÎÒÃǶ¼ÖªµÀ£¬rand²úÉúµÄÊÇαËæ»úÊý£¬ÔÚCÖÐÐèÒªÓÃsrandÏÔʾָ¶¨ÖÖ×Ó¡£µ«ÊÇÔÚphpÖУ¬rand»á×Ô¼º°ïÄãĬÈϵ÷ÓÃÒ»´Îsrand£¬Ò»°ãÇé¿öϲ»ÐèÒª×Ô¼ºÔÙÏÔʾµÄµ÷Óá£
ÐèҪעÒâµÄÊÇ£¬Èç¹ûÌØÊâÇé¿öÏÂÐèÒªµ÷ÓÃsrandʱ£¬Ò»¶¨ÒªÅäÌ×µ÷Ó᣾ÍÊÇ˵srand¶ÔÓÚrand£¬mt_srand¶ÔÓ¦srand£¬Çв»¿É»ìºÏʹÓ㬷ñÔòÊÇÎÞЧµÄ¡£
sortºÍusort
Á½Õ߶¼ÊÇÓÃÓÚÅÅÐò£¬²»Í¬µÄÊÇÇ°Õß¿ÉÒÔÖ¸¶¨ÅÅÐò²ßÂÔ£¬ÀàËÆÎÒÃÇCÀïÃæµÄqsortºÍC++µÄsort¡£
ÔÚÅÅÐòÉÏÁ½Õ߶¼ÊDzÉÓñê×¼µÄ¿ìÅÅÀ´ÊµÏÖ£¬¶ÔÓÚÓÐÅÅÐòÐèÇóµÄ£¬Èç·ÇÌØÊâÇé¿öµ÷ÓÃphpÌṩµÄÕâЩ·½·¨¾Í¿ÉÒÔÁË£¬²»ÓÃ×Ô¼ºÖØÐÂʵÏÖÒ»±é£¬Ð§ÂÊ»áµÍºÜ¶à¡£ÔÒò¼ûÇ°ÎĶÔÓÚÓû§º¯ÊýºÍÄÚÖú¯ÊýµÄ·ÖÎö±È¶Ô¡£
urlencodeºÍrawurlencode
ÕâÁ½¸ö¶¼ÊÇÓÃÓÚurl±àÂ룬 ×Ö·û´®ÖгýÁË -_. Ö®ÍâµÄËùÓзÇ×ÖĸÊý×Ö×Ö·û¶¼½«±»Ìæ»»³É°Ù·ÖºÅ£¨%£©ºó¸úÁ½Î»Ê®Áù½øÖÆÊý¡£Á½ÕßΨһµÄÇø±ðÔÚÓÚ¶ÔÓÚ¿Õ¸ñ£¬urlencode»á±àÂëΪ+£¬¶ørawurlencode»á±àÂëΪ ¡£
Ò»°ãÇé¿öϳýÁËËÑË÷ÒýÇ棬ÎÒÃǵIJßÂÔ¶¼ÊÇ¿Õ¸ñ±àÂëΪ ¡£Òò´Ë²ÉÓúóÕߵľӶࡣ
×¢ÒâµÄÊÇencodeºÍdecodeϵÁÐÒ»¶¨ÒªÅäÌ×ʹÓá£
strcmpϵÁк¯Êý
ÕâһϵÁеĺ¯Êý°üÀ¨strcmp¡¢strncmp¡¢strcasecmp¡¢strncasecmp£¬ÊµÏÖ¹¦ÄܺÍCº¯ÊýÏàͬ¡£µ«Ò²Óв»Í¬£¬ÓÉÓÚphpµÄ×Ö·û´®ÊÇÔÊÐí\0³öÏÖ£¬Òò´ËÔÚÅжϵÄʱºòµ×²ãʹÓõÄÊÇmemcmpϵÁжø·Çstrcmp£¬ÀíÂÛÉÏÀ´Ëµ¸ü¿ì¡£
ÁíÍâÓÉÓÚphpÖ±½ÓÄÜ»ñÈ¡µ½×Ö·û´®³¤¶È£¬Òò´Ë»áÊ×ÏÈÕâ·½ÃæµÄ¼ì²é£¬ºÜ¶àÇé¿öÏÂЧÂʾͻá¸ßºÜ¶àÁË¡£
is_intºÍis_numeric
ÕâÁ½¸öº¯Êý¹¦ÄÜÏàËÆÓÖ²»ÍêÈ«Ïàͬ£¬Ê¹ÓõÄʱºòÒ»¶¨ÐèҪעÒâËûÃǵÄÇø±ð¡£
Is_int£ºÅжÏÒ»¸ö±äÁ¿ÀàÐÍÊÇ·ñÊÇÕûÊýÐÍ£¬php±äÁ¿ÖÐרÃÅÓÐÒ»¸ö×ֶαíÕ÷ÀàÐÍ£¬Òò´ËÖ±½ÓÅжÏÕâ¸öÀàÐͼ´¿É£¬ÊÇÒ»¸ö¾ø¶ÔO(1)µÄ²Ù×÷
Is_numeric£ºÅжÏÒ»¸ö±äÁ¿ÊÇ·ñÊÇÕûÊý»òÊý×Ö×Ö·û´®£¬Ò²¾ÍÊÇ˵³ýÁËÕûÊýÐͱäÁ¿»á·µ»ØtrueÖ®Í⣬¶ÔÓÚ×Ö·û´®±äÁ¿£¬Èç¹ûÐÎÈ硱1234¡±£¬¡±1e4¡±µÈÒ²»á±»ÅÐΪtrue¡£Õâ¸öʱºò»á±éÀú×Ö·û´®½øÐÐÅжϡ£
ÍƼöÐÅÏ¢
- ¡¾ÊÓƵ²¥·Å¡¿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¼ì²â×Ö·û´®±àÂë
ÆÀÂÛ