rmpotter Posted July 31, 2009 Share Posted July 31, 2009 I am trying to figure out how to take an array of values and upload them into a single SQL field so that I can use the eval() function to re-populate the array on retrieval. Can anyone help me? Link to comment Share on other sites More sharing options...
gekk0 Posted July 31, 2009 Share Posted July 31, 2009 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.