serialize()
is the function you are looking for. It will return a string representation of its input array or object in a PHP-specific internal format. The string may be converted back to its original form with unserialize()
.
But beware, that not all objects are serializable, or some may be only partially serializable and unable to be completely restored with unserialize()
.
$array = array(1,2,3,'foo');
echo serialize($array);
// Prints
a:4:{i:0;i:1;i:1;i:2;i:2;i:3;i:3;s:3:"foo";}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…