save arrays into database

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
        )

)

3 Comments Leave a Comment

Cine [ Quote ]

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

February 28th, 2005 at 11:18 am
Daynah [ Quote ]

Thanks for sharing sis! :) I didn’t know that. hehe

February 28th, 2005 at 11:35 pm
Anna [ Quote ]

Beyond wonder…I don’t understand a thing ^^

March 1st, 2005 at 7:47 pm

Leave a Comment Name, email and comment are required.
Email will never be displayed.

Leave a Comment
  1. :biggrin: :blank: :blush: :bored: :confused: :cool: :down: :evil: :frown: :grin: :grr: :laidback: :left: :mad: :right: :sad: :secret: :shock: :smile: :stress: :tongue: :up: :wink: :yawn: :cute: :dead: :film: :floppy: :glasses: :grumpy: :headphones: :heart: :lightbulb: :ouch: :tv: :upsidedown: :vodka: :yell: :yuck: :yummy: