How can PHP serialize and unserialize functions be used to store arrays in a database?
When storing arrays in a database using PHP, you can serialize the array before saving it to the database and unserialize it when retrieving it. This allows you to store complex data structures like arrays in a single database field.
// Serialize the array before storing it in the database
$array = [1, 2, 3, 'hello'];
$serializedArray = serialize($array);
// Save $serializedArray to the database
// Retrieve the serialized array from the database
// Assume $serializedArray is fetched from the database
$unserializedArray = unserialize($serializedArray);
// $unserializedArray will now contain the original array [1, 2, 3, 'hello']