PHP序列化變數的3種方法

jieforest發表於2012-07-17
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/,如需轉載,請註明出處,否則將追究法律責任。

相關文章