unserialize
(PHP3 >= 3.0.5 , PHP4)
unserialize --- 从储存的值中建立PHP的值
语法 :
mixed unserialize
(string str)说明 :
unserialize( )取一个serialized变量(参考serialize( )),并且将它转换回PHP的值,传回转换后的值,而且可以是integer、double、string、array、object。如果物件有serialized,则它的方法不会保存在所传回的值之中。
Example :
<?php
// Here, we use unserialize() to load session data from a database
// into $session_data. This example complements the one described
// with serialize( ).
$conn = odbc_connect ("webdb", "php", "chicken");
$stmt = odbc_prepare ($conn, "SELECT data FROM sessions WHERE id = ?");
$sqldata = array ($PHP_AUTH_USER);
if (!odbc_execute ($stmt, &$sqldata) || !odbc_fetch_into ($stmt, &$tmp)) {
// if the execute or fetch fails, initialize to empty array
$session_data = array();
} else {
// we should now have the serialized data in $tmp[0].
$session_data = unserialize ($tmp[0]);
if (!is_array ($session_data)) {
// something went wrong, initialize to empty array
$session_data = array();
}
}
?>