Array to string conversion in php shell code] code example
Example 1: php Array to string conversion
Using implode() function in Php
-----------------------
Syntax
implode(separator,array);
Example
<?php
$dummyArr = array("Hello","Greppers,","Ankur","here !");
echo implode(" ",$dummyArr);
?>
Output:
Hello Greppers, Ankur here !
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);