serialize --
Generates a storable representation of a value
Syntax
string serialize ( mixed value )
serialize() returns a string containing a
byte-stream representation of value that
can be stored anywhere.
This is useful for storing or passing PHP values around without
losing their type and structure.
To make the serialized string into a PHP value again, use
unserialize(). serialize()
handles all types, except the resource-type.
You can even serialize() arrays that contain
references to itself. References inside the array/object you
are serialize()ing will also be stored.
When serializing objects, PHP will attempt to call the member function
__sleep() prior to serialization. This is to allow the
object to do any last minute clean-up, etc. prior to being serialized.
Likewise, when the object is restored using unserialize()
the __wakeup() member function is called.
Note:
This didn't work correctly until 4.0.7.
Note:
In PHP 3, object properties will be serialized, but methods are
lost. That limitation was removed in PHP 4 as both properties
and methods are now restored. Please see the Serializing Objects
section of Classes and
Objects for more information.
It is not possible to serialize PHP built-in objects.
Example 1. serialize() example
<?php // $session_data contains a multi-dimensional array with session // information for the current user. We use serialize() to store // it in a database at the end of the request.
$conn = odbc_connect("webdb", "php", "chicken"); $stmt = odbc_prepare($conn, "UPDATE sessions SET data = ? WHERE id = ?"); $sqldata = array (serialize($session_data), $PHP_AUTH_USER); if (!odbc_execute($stmt, &$sqldata)) { $stmt = odbc_prepare($conn, "INSERT INTO sessions (id, data) VALUES(?, ?)"); if (!odbc_execute($stmt, &$sqldata)) { /* Something went wrong.. */ } } ?>
serialize php code on this is provided for your study purpose, it will guide you to know how create and design a website using php. use it to practice and train your self online
Php serialize syntax tutorial
php tutorial guide and code design are for easy learning and programming. The code practice section provided at the top is for practising of this syntax. Use the code section up to practice your php programming online. Learning php is very easy, all you need is to use the examples on this site and practice them to perfect your skills.