how to turn array into string php code example
Example 1: Convert an Array to a String in PHP
phpCopy<?php
$array = ["Lili", "Rose", "Jasmine", "Daisy"];
$JsonObject = serialize($array);
echo "The array is converted to the Json string.";
echo "\n";
echo"The Json string is $JsonObject";
?>
Example 2: array to string conversion in php
function subArraysToString($ar, $sep = ', ') {
$str = '';
foreach ($ar as $val) {
$str .= implode($sep, $val);
$str .= $sep;
}
$str = rtrim($str, $sep);
return $str;
}
echo subArraysToString($food);