Skip to content

php store array in database ?

Array can be stored in database in the form of string.we can use serialize function to make storable representation of array.we can also get back from that string to array using unserialize function.eg.

<?php
$arr=array(“India”,”Pakistan”,”Sri Lanka”,”Bangladesh”);
//process of serialization
$newString=serialize($arr);
//it will produce following output
a:4:{i:0;s:5:”India”;i:1;s:8:”Pakistan”;i:2;s:9:”Sri Lanka”;i:3;s:10:”Bangladesh”;}
//process of unserialization
$arr=unserialize($newString);
print_r($arr);

//it will produce following output
Array ( [0] => India [1] => Pakistan [2] => Sri Lanka [3] => Bangladesh )

?>

Leave a Reply

Your email address will not be published.

3 + 7 =