ArrayObject::serialize


Serialize an ArrayObject.



<?php

str 
public ArrayObject::serialize void )

?>

  1 EXERCISE   

<?php

$Dwarfs 
= [ => 'Bashful'=> 'Doc'
                   
=> 'Grumpy'=> 'Happy'
                   
=> 'Sneezy'=> 'Sleepy'=> 'Dopey'
                   
=> 'Snow White'];

$dwArrayObject = new ArrayObject($Dwarfs);

$str01 serialize($dwArrayObject);

$str02 $dwArrayObject->serialize();

echo 
$str01 '<br><br>' $str02;

?>

 RESULT   

[ 01 ] SERIALIZED ArrayObject

x:i:0;a:8:{i:1;s:7:"Bashful";i:2;s:3:"Doc";i:3;s:6:"Grumpy";i:4;s:5:"Happy";i:5;s:6:"Sneezy";i:6;s:6:"Sleepy";i:7;s:5:"Dopey";i:8;s:10:"Snow White";};m:a:0:{}

[ 02 ] SERIALIZED ArrayObject

x:i:0;a:8:{i:1;s:7:"Bashful";i:2;s:3:"Doc";i:3;s:6:"Grumpy";i:4;s:5:"Happy";i:5;s:6:"Sneezy";i:6;s:6:"Sleepy";i:7;s:5:"Dopey";i:8;s:10:"Snow White";};m:a:0:{}


  2 EXERCISE   

<?php

class Dwarfs
{
const 
MYARRAY = [ => 'Bashful'=> 'Doc'
                   
=> 'Grumpy'=> 'Happy'
                   
=> 'Sneezy'=> 'Sleepy'=> 'Dopey'
                   
=> 'Snow White'];
    
    
public static function 
serialz()
{
    return 
serialize(self::MYARRAY);
}

}

var_dump(Dwarfs::serialz());

?>

 RESULT   

[ 03 ] SERIALIZED ArrayObject

O:11:"ArrayObject":3:{i:0;i:0;i:1;a:8:{i:1;s:7:"Bashful";i:2;s:3:"Doc";i:3;s:6:"Grumpy";i:4;s:5:"Happy";i:5;s:6:"Sneezy";i:6;s:6:"Sleepy";i:7;s:5:"Dopey";i:8;s:10:"Snow White";}i:2;a:0:{}}