PHP ÐòÁл¯£¨serialize£©¸ñʽÏê½â(3)
5.2£®ÒýÓñêʾºóµÄÊý×Ö
ÔÚÉÏÃæµÄÀý×ÓÖдó¼Ò¿ÉÄÜÒѾ¿´µ½ÁË£¬¶ÔÏóÒýÓã¨r£©ºÍÖ¸ÕëÒýÓã¨R£©µÄ¸ñʽΪ£º
r:<number>; R:<number>;´ó¼ÒÒ»¶¨ºÜÆæ¹ÖºóÃæÕâ¸ö <number> ÊÇʲô°É£¿±¾½ÚÎÒÃǾÍÀ´ÏêϸÌÖÂÛÕâ¸öÎÊÌâ¡£
Õâ¸ö <number> ¼òµ¥µÄ˵£¬¾ÍÊÇËùÒýÓõĶÔÏóÔÚÐòÁл¯´®ÖеÚÒ»´Î³öÏÖµÄλÖ㬵«ÊÇÕâ¸öλÖò»ÊÇÖ¸×Ö·ûµÄλÖ㬶øÊÇÖ¸¶ÔÏó£¨ÕâÀïµÄ¶ÔÏóÊÇ·ºÖ¸ËùÓÐÀàÐ͵ÄÁ¿£¬¶ø²»½öÏÞÓÚ¶ÔÏóÀàÐÍ£©µÄλÖá£
ÎÒÏë´ó¼Ò¿ÉÄÜ»¹²»ÊǺÜÃ÷°×£¬ÄÇôÎÒÀ´¾ÙÀý˵Ã÷һϣº
class ClassA { var $int; var $str; var $bool; var $obj; var $pr; } $a = new ClassA(); $a->int = 1; $a->str = "Hello"; $a->bool = false; $a->obj = $a; $a->pr = &$a->str; echo serialize($a);Õâ¸öÀý×ӵĽá¹ûÊÇ£º
O:6:"ClassA":5:{s:3:"int";i:1;s:3:"str";s:5:"Hello";s:4:"bool";b:0;s:3:"obj";r:1;s:2:"pr";R:3;}
ÔÚÕâ¸öÀý×ÓÖУ¬Ê×ÏÈÐòÁл¯µÄ¶ÔÏóÊÇ ClassA µÄÒ»¸ö¶ÔÏó£¬ÄÇô¸øËü±àºÅΪ 1£¬½ÓÏÂÀ´ÒªÐòÁл¯µÄÊÇÕâ¸ö¶ÔÏóµÄ¼¸¸ö³ÉÔ±£¬µÚÒ»¸ö±»ÐòÁл¯µÄ³ÉÔ±ÊÇ int ×ֶΣ¬ÄÇËüµÄ±àºÅ¾ÍΪ 2£¬½ÓÏÂÀ´±»ÐòÁл¯µÄ³ÉÔ±ÊÇ str£¬ÄÇËüµÄ±àºÅ¾ÍÊÇ 3£¬ÒÀ´ËÀàÍÆ£¬µ½ÁË obj ³ÉԱʱ£¬Ëü·¢ÏָóÉÔ±ÒѾ±»ÐòÁл¯ÁË£¬²¢ÇÒ±àºÅΪ 1£¬Òò´ËËü±»ÐòÁл¯Ê±£¬¾Í±»ÐòÁл¯³ÉÁË r:1; £¬ÔÚ½ÓÏÂÀ´±»ÐòÁл¯µÄÊÇ pr ³ÉÔ±£¬Ëü·¢ÏָóÉԱʵ¼ÊÉÏÊÇÖ¸Ïò str ³ÉÔ±µÄÒ»¸öÒýÓ㬶ø str ³ÉÔ±µÄ±àºÅΪ 3£¬Òò´Ë£¬pr ¾Í±»ÐòÁл¯Îª R:3; ÁË¡£
PHP ÊÇÈçºÎÀ´±àºÅ±»ÐòÁл¯µÄ¶ÔÏóµÄÄØ£¿Êµ¼ÊÉÏ£¬PHP ÔÚÐòÁл¯Ê±£¬Ê×ÏȽ¨Á¢Ò»¸ö¿Õ±í£¬È»ºóÿ¸ö±»ÐòÁл¯µÄ¶ÔÏóÔÚ±»ÐòÁл¯Ö®Ç°£¬¶¼ÐèÒªÏȼÆËã¸Ã¶ÔÏóµÄ Hash Öµ£¬È»ºóÅжϸà Hash ÖµÊÇ·ñÒѾ³öÏÖÔڸñíÖÐÁË£¬Èç¹ûûÓгöÏÖ£¬¾Í°Ñ¸Ã Hash ÖµÌí¼Óµ½Õâ¸ö±íµÄ×îºó£¬·µ»ØÌí¼Ó³É¹¦¡£Èç¹û³öÏÖÁË£¬Ôò·µ»ØÌí¼Óʧ°Ü£¬µ«ÊÇÔÚ·µ»Øʧ°ÜÇ°ÏÈÅжϸöÔÏóÊÇ·ñÊÇÒ»¸öÒýÓã¨Óà & ·ûºÅ¶¨ÒåµÄÒýÓã©£¬Èç¹û²»ÊÇÔòÒ²°Ñ Hash ÖµÌí¼Óµ½±íºó£¨¾¡¹Ü·µ»ØµÄÊÇÌí¼Óʧ°Ü£©¡£Èç¹û·µ»Øʧ°Ü£¬Ôòͬʱ·µ»ØÉÏÒ»´Î³öÏÖµÄλÖá£
ÔÚÌí¼Ó Hash Öµµ½±íÖÐÖ®ºó£¬Èç¹ûÌí¼Óʧ°Ü£¬ÔòÅжÏÌí¼ÓµÄÊÇÒ»¸öÒýÓû¹ÊÇÒ»¸ö¶ÔÏó£¬Èç¹ûÊÇÒýÓã¬Ôò·µ»Ø R ±êʾ£¬Èç¹ûÊǶÔÏó£¬Ôò·µ»Ø r ±êʾ¡£ÒòΪʧ°Üʱ£¬»áͬʱ·µ»ØÉÏÒ»´Î³öÏÖµÄλÖã¬Òò´Ë£¬R ºÍ r ±êʾºóÃæµÄÊý×Ö£¬¾ÍÊÇÕâ¸öλÖá£
5.3£®¶ÔÏóÒýÓõķ´ÐòÁл¯
PHP ÔÚ·´ÐòÁл¯´¦Àí¶ÔÏóÒýÓÃʱºÜÓÐÒâ˼£¬Èç¹û·´ÐòÁл¯µÄ×Ö·û´®²»ÊÇ PHP µÄ serialize() ±¾ÉíÉú³ÉµÄ£¬¶øÊÇÈËΪ¹¹Ôì»òÕßÓÃÆäËüÓïÑÔÉú³ÉµÄ£¬¼´Ê¹¶ÔÏóÒýÓÃÖ¸ÏòµÄ²»ÊÇÒ»¸ö¶ÔÏó£¬ËüÒ²ÄÜÕýÈ·µØ°´ÕÕ¶ÔÏóÒýÓÃËùÖ¸ÏòµÄÊý¾Ý½øÐз´ÐòÁл¯¡£ÀýÈ磺
echo "<pre>"; class StrClass { var $a; var $b; } $a = unserialize('O:8:"StrClass":2:{s:1:"a";s:5:"Hello";s:1:"b";r:2;}'); var_dump($a); echo "</pre>";ÔËÐнá¹û£º
object(StrClass)#1 (2) { ["a"]=> string(5) "Hello" ["b"]=> string(5) "Hello" }´ó¼Ò»á·¢ÏÖ£¬ÉÏÃæµÄÀý×Ó·´ÐòÁл¯ºó£¬$a->b µÄÖµÓë $a->a µÄÖµÊÇÒ»ÑùµÄ£¬¾¡¹Ü $a->a ²»ÊÇÒ»¸ö¶ÔÏ󣬶øÊÇÒ»¸ö×Ö·û´®¡£Òò´ËÈç¹û´ó¼ÒÓÃÆäËüÓïÑÔÀ´ÊµÏÖÐòÁл¯µÄ»°£¬²»Ò»¶¨·ÇÒª°Ñ string ×÷Ϊ±êÁ¿ÀàÐÍÀ´´¦Àí£¬¼´Ê¹°´ÕÕ¶ÔÏóÒýÓÃÀ´ÐòÁл¯ÓµÓÐÏàͬ×Ö·û´®ÄÚÈݵĸ´ºÏÀàÐÍ£¬Óà PHP ͬÑù¿ÉÒÔÕýÈ·µÄ·´ÐòÁл¯¡£ÕâÑù¿ÉÒÔ¸ü½ÚÊ¡ÐòÁл¯ºóµÄÄÚÈÝËùÕ¼ÓõĿռ䡣
ÍƼöÐÅÏ¢
- ¡¾ÊÓƵ²¥·Å¡¿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¼ì²â×Ö·û´®±àÂë
ÆÀÂÛ