PHP/Utility Function/unserialize

Материал из Web эксперт
Перейти к: навигация, поиск

convert the string produced by serialize() back into an object with the unserialize() function.

 
<?
class apple {
  var $flavor="sweet";
}
$app = new apple();
$stored = serialize( $app );
print $stored;
$new_app = unserialize( $stored );
print $new_app->flavor;
?>



Encapsulating Complex Data Types

 
<?php 
$fruits = array("apple", "orange", "apple"); 
$str = serialize($fruits); 
echo "$str\n"; 
$new_fruits = unserialize($str); 
$new_fruits[] = "apple"; 
print_r($new_fruits); 
?>



Serialize and unserialize array

 
<?php
$arr = array("apple", "orange", "pear");
define("MYARRAY", serialize($arr));
function MyTest() {
  print_r(unserialize(MYARRAY));
}
MyTest();
?>