Convert an Array to a String in 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: Convert an Array to a String in PHP

phpCopy<?php   
$arr = array("This","is", "an", "array");  
$string = implode(" ",$arr);  
echo "The array is converted to the string.";
echo "\n";
echo "The string is '$string'";
?>

Example 3: Convert an Array to a String in PHP

phpCopy<?php
   $array = ["Lili", "Rose", "Jasmine", "Daisy"];
   $JsonObject = json_encode($array);
   echo "The array is converted to the Json string.";
   echo "\n"; 
   echo"The Json string is $JsonObject";
?>

Example 4: Convert an Array to a String in PHP

phpCopyjson_encode( $ArrayName );

Example 5: Convert an Array to a String in PHP

phpCopyimplode($string, $arrayName);

Example 6: Convert an Array to a String in PHP

phpCopyserialize($ArrayName);

Tags:

Php Example