Sometime you may need to pass the array in the url.
You can do this as following:
<?php
$array["a"] = "A";
$array["b"] = "B";
$array["c"] = "C";
$array["d"] = "D";
$str = serialize($array);
$strenc = urlencode($str);
print $str . "\n";
print $strenc . "\n"; ?>
This ll give you :
a:4:{s:1:"a";s:8:"Thusitha";s:1:"b";s:10:"Sumanadasa";s:1:"c";s:6:"Lakmal";s:1:"d";s:11:"Nanayakkara";}
and
a%3A4%3A%7Bs%3A1%3A%22a%22%3Bs%3A8%3A%22Thusitha%22%3Bs%3A1%3A%22b%22%3Bs%3A10%3A%22Sumanadasa%22%3Bs%3A1%3A%22c%22%3Bs%3A6%3A%22Lakmal%22%3Bs%3A1%3A%22d%22%3Bs%3A11%3A%22Nanayakkara%22%3B%7D
Serialize will give you the storable representation of the array:
This is useful for storing or passing PHP values around without losing their type and structure.
$url ='http://page_no_2.php?data=".$strenc."';
If you want to pass this array to some other page in url you need to unserialize the data from url
<?php
$strenc2= $_GET['data'];
$arr = unserialize(urldecode($strenc2));
var_dump($arr);
?>
o/p:
array(4) {
["a"]=>
string(8) "A"
["b"]=>
string(10) "B"
["c"]=>
string(6) "C"
["d"]=>
string(11) "D"
}
0 Comment(s)