Updating a serialized array.
First off we all should know how to use serialize().
Serialize is a function that takes arrays into strings for easier storing.
So in this tutorial you will learn how to update a serialize array.
First off lets create our array:
<?php
$array = array(1 => "one");
?>
To serialize arrays all you do is put the array between the parameters for the serialize function like so:
<?php
$array = array(1 => "one");
$a = serialize($array);
?>
This will output the following:
a:1:{i:1;s:3:"one";}
Now lets unserialize the $a variable and update the array.
<?php
$array = array(1 => "one");
$a = serialize($array);
$arrah = unserialize($a);
?>
This above would output the array back into array form using $arrah to access its values.
<?php
$array = array(1 => "one");
$a = serialize($array);
$arrah = unserialize($a);
$arrah[1] = "uno";
$arrah[2] = "two";
$thearray = serialize($arrah);
?>
Alright how serialize works is when you unserialize arrays there already in array form so everytime you add a array like so:
array
It will either add another key/value or update a key/value of an already existing array.
Now thats the basics on how to update a serialized array in PHP.
Have fun its useful.
Example:
http://www.nbboard.zoomcities.com/serialize.phpIf can't view link heres result:
<?php
$array = serialize(array(1 => "one"));
echo $array;
$array2 = unserialize($array);
$array2[1] = "uno";
$array2[2] = "two";
$arrah = serialize($array2);
echo "<br />".$arrah;
?>
a:1:{i:1;s:3:"one";}
a:2:{i:1;s:3:"uno";i:2;s:3:"two";}