save arrays into database
February 28th, 2005
i’ve known this for a while but forgot to share it. there is a very easy way you can store array into database as a string. then you can grab the string from the database and convert it back into an array.
code example:
<?php
$myarray[] = "meow";
$myarray[] = "woof";
$myarray[meow] = "cool";
$myarray[woof] = "cool";
$myarray[thisrules][0] = "Mmmm";
$text_myarray = serialize($myarray);
// store it into my database (depend on the length of your array, declare the comµçVÖâ2FW‡B÷"f&6†"’ ТòòVÆÂ—B÷WBöb×’FF&6RÂ7W÷6RF÷WEööeöוöFF&6R7F÷&W2F†RFW‡Bg&öÒ–÷W"FF&6R6öÛ^umn
// then $get_myarray = unserialize($out_of_my_database); echo "<pre>"; print_r($get_myarray);
?>
you should get
Array
(
[0] => meow
[1] => woof
[meow] => cool
[woof] => cool
[thisrules] => Array
(
[0] => Mmmm
)
)
I didn’t know that. hehe

Woah, that is so awesome. Definitely helpful, thanks a lot.