Opensource, CMS, PHP, MySql, Drupal, Frameworks

Wednesday, July 20, 2011

php serialize and unserialize

This process makes a storable representation of a value that is useful for storing or passing PHP values around without losing their type and structure.

<?php
    $the_array = array( "Merriet", "Jerry", "Drupal", "PHP" );
    $serialized = serialize($the_array);
    print $serialized.'<br/>';
    print_r(unserialize($serialized));
?>

Output:
Serialize: a:4:{i:0;s:7:"Merriet";i:1;s:5:"Jerry";i:2;s:6:"Drupal";i:3;s:3:"PHP";}
Unserialize: Array ( [0] => Merriet [1] => Jerry [2] => Drupal [3] => PHP )