serialize()
Storing an object or array can be a tricky thing, but this function makes it simple. It will transform any value into a string version of that value without losing its type or structure.
The resulting string is of a different format and is not meant to be used directly but for writing to a file or database, or used anywhere you need to transfer data but are restricted to string format. On the other side, use unserialize() to bring back the original array, object, etc.
$arr = array( 'a' => 'apple', 'b' => false, 'c' => 'monkey' ); $obj = new stdClass(); $obj->one = 1; $obj->two = 'too'; $x = serialize( $arr ); // a:3:{s:1:"a";s:5:"apple";s:1:"b";b:0;s:1:"c";s:6:"monkey";} $y = serialize( $obj ); // O:8:"stdClass":2:{s:3:"one";i:1;s:3:"two";s:3:"too";} $z = serialize( 17 ); // i:17;
See the manual entry for serialize()
