In PHP, how do I serialize arrays with built-in functions?

Serializing Arrays in PHP

In PHP, you can serialize arrays using built-in functions like serialize() and json_encode(). These functions convert an array into a storable string format that can be easily saved to a file or passed between different programming environments.

Example of Serializing Arrays

<?php // Example array $array = array('name' => 'John', 'age' => 30, 'city' => 'New York'); // Using serialize() $serializedArray = serialize($array); echo "Serialized Array: " . $serializedArray . "<br>"; // Using json_encode() $jsonArray = json_encode($array); echo "JSON Array: " . $jsonArray; ?>

serializing arrays PHP arrays serialize function json_encode function