PHP/Utility Function/unserialize

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

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

   <source lang="html4strict">

<? class apple {

 var $flavor="sweet";

} $app = new apple(); $stored = serialize( $app ); print $stored; $new_app = unserialize( $stored ); print $new_app->flavor; ?>

 </source>
   
  


Encapsulating Complex Data Types

   <source lang="html4strict">

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

 </source>
   
  


Serialize and unserialize array

   <source lang="html4strict">

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

 print_r(unserialize(MYARRAY));

} MyTest(); ?>

 </source>