Jump to content

Uploading An Array Of Values Into Sql


rmpotter

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

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...