How to serialize an array in php?

How to serialize an array in php?

Team Leader Asked on February 11, 2017 in PHP.
Add Comment
1 Answer(s)

    The function serialize() generates a storable representation of a value.The Unserialize() is used to convert the string back to an PHP object.

     

    
    <?php
    
    $arr= array("1","2","3");
    
    print_r($arr);
    
    echo "<br>";
    
    $s1=serialize($arr);
    
    echo $s1;
    
    echo "<br>";
    
    $uns=unserialize($s1);
    
    print_r($uns);
    
    ?>
    
    

    OUTPUT

    
    Array ( [0] => 1 [1] => 2 [2] => 3 )
    
    a:3:{i:0;s:1:"1";i:1;s:1:"2";i:2;s:1:"3";}
    
    Array ( [0] => 1 [1] => 2 [2] => 3 )
    
    
    IT Head Answered on June 29, 2017.
    Add Comment

    Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.