
Suppose that you are dealing with an associate array in php. The code below will show you to serialize the array variable, thus allowing the data to be saved in a single column in a database.
The Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<?php //serializing will allow data to be saved in a single column in a database $serialized_data = serialize(array( array("resultid" => "4", "association" => "0", "answer" => "answer1"), array("resultid" => "5", "association" => "0", "answer" => "answer2"), array("resultid" => "6", "association" => "2", "answer" => "answer3"), )); // the $serialized_data can be saved as a string value in your database echo $serialized_data . '<br>'; // later on, your can retrieve the serialized data string from your database // Unserialize the data to convert the variable back into an array $var1 = unserialize($serialized_data); // Show the unserialized data; var_dump ($var1); echo $var1[0]["answer"]; ?> |