ITPub博客

首页 > Linux操作系统 > Linux操作系统 > PHP序列化变量的3种方法

PHP序列化变量的3种方法

原创 Linux操作系统 作者:jieforest 时间:2012-07-17 03:16:13 0 删除 编辑
The idea behind serializing a variable is to create a storable string format of it, such that the same variable can be recreated later when required using the string.

1. serialize and unserialize

These are the traditional functions to serialize and unserialize data in PHP.

CODE:

$a = array('a' => 'Apple' ,'b' => 'banana' , 'c' => 'Coconut');

//serialize the array
$s = serialize($a);
echo $s;
//a:3:{s:1:"a";s:5:"Apple";s:1:"b";s:6:"banana";s:1:"c";s:7:"Coconut";}

echo '

';

//unserialize
$o = unserialize($s);

print_r($o);

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/301743/viewspace-735652/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2008-04-23

  • 博文量
    443
  • 访问量
    508545