龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > web编程 > php编程 >

php序列化

时间:2014-07-22 14:52来源: 作者: 点击:
分享到:
<无详细内容>
// a complex array
$myvar = array(
 'hello',
 42,
 array(1,'two'),
 'apple'
);
 
// convert to a string
$string = serialize($myvar);
 
echo $string;
/* prints
a:4:{i:0;s:5:"hello";i:1;i:42;i:2;a:2:{i:0;i:1;i:1;s:3:"two";}i:3;s:5:"apple";}
*/
 
// you can reproduce the original variable
$newvar = unserialize($string);
 
print_r($newvar);
/* prints
Array
(
    [0] => hello
    [1] => 42
    [2] => Array
        (
            [0] => 1
            [1] => two
        )
 
    [3] => apple
)
*/

2. [代码][PHP]代码     跳至 [1] [2] [全屏预览]

//由于 JSON 近年来大受欢迎,PHP5.2 中已经加入了对 JSON 格式的支持。现在你可以使用 json_encode() 和 json_decode() 函数:
 
 
// a complex array
$myvar = array(
 'hello',
 42,
 array(1,'two'),
 'apple'
);
 
// convert to a string
$string = json_encode($myvar);
 
echo $string;
/* prints
["hello",42,[1,"two"],"apple"]
*/
 
// you can reproduce the original variable
$newvar = json_decode($string);
 
print_r($newvar);
/* prints
Array
(
    [0] => hello
    [1] => 42
    [2] => Array
        (
            [0] => 1
            [1] => two
        )
 
    [3] => apple
)
*/
精彩图集

赞助商链接