maniclorn maniclorn - 5 months ago 39
PHP Question

How to convert array to a string using methods other than JSON?

What is a function in PHP used to convert array to string, other than using JSON?

I know there is a function that directly does like JSON. I just don't remember.


serialize() is the function you are looking for. It will return a string representation of its input array or object in a PHP-specific internal format. The string may be converted back to its original form with unserialize().

But beware, that not all objects are serializable, or some may be only partially serializable and unable to be completely restored with unserialize().

$array = array(1,2,3,'foo');
echo serialize($array);

// Prints