Jump to content

Uploading An Array Of Values Into Sql


Recommended Posts

I'd use something like serialize() to store it in the database, then when you read it, use unserialize(), like this:

<?php$array = array('one' => '1','two' => '2','three' => '3','four' => '4','five' => '5');$serialized = serialize($array);echo $serialized . '<br><br><br>';$arrayTwo = unserialize($serialized);echo '<pre>';print_r($arrayTwo);echo '</pre>';?>

that will output this:

a:5:{s:3:"one";s:1:"1";s:3:"two";s:1:"2";s:5:"three";s:1:"3";s:4:"four";s:1:"4";s:4:"five";s:1:"5";}Array(	[one] => 1	[two] => 2	[three] => 3	[four] => 4	[five] => 5)

no need to use eval(), serialize turns the array into a storable form, then unserialize() turns it back into an array

Edited by gekk0
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...