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.
JavaScript Array toString() The toString() method returns a string with array values separated by commas. The toString() method does not change the original array.
We can use Arrays. toString method that invoke the toString() method on individual elements and use StringBuilder to create String. We can also create our own method to convert String array to String if we have some specific format requirements.
The toString() method is used for converting and representing an array into string form. It returns the string containing the specified array elements.
To convert an array of numbers to an array of strings, call the map() method on the array, and on each iteration, convert the number to a string. The map method will return a new array containing only strings. Copied! const arrOfNum = [1, 2, 3]; const arrOfStr = arrOfNum.
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 a:4:{i:0;i:1;i:1;i:2;i:2;i:3;i:3;s:3:"foo";}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With