serialize(),unserialize()

1.关联数组 序列化

$array = array();
$array['key'] = 'website';
$array['value']='www.isoji.org';
$b = serialize($array);  /*serialize()返回字符串
echo $b;                       // 输出    a:2:{s:3:"key";s:7:"website";s:5:"value";s:13:"www.isoji.org";}  



unset($array);  
$b = unserialize($b);
print_r($b);                 //输出   Array ( [key] => website [value] => www.isoji.org )

2.索引数组序列化
$array = array(); 
$array[] = 'website'; 
$array[]='www.chhua.com'; 
$a = serialize($array); 
echo $a;                  //a:2:{i:0;s:7:"website";i:1;s:13:"www.chhua.com";}



unset($array); 
$a = unserialize($a); 
print_r($a);            //Array ( [0] => website [1] => www.chhua.com )
 

 

posted on 2018-05-20 11:55  running-fly  阅读(171)  评论(0编辑  收藏  举报

导航