Asked 3 years ago
30 Jul 2021
Views 669
Weldon

Weldon posted

Convert array to string in PHP

Convert array to string in PHP
Melyna

Melyna
answered Aug 22 '21 17:29

implode() function is can convert the array to string in PHP.


$array=array("array",,"is""string","now");
echo implode(" ",$array); // it print array is string now



implode("first argument is glue","second argument must be
array ")


so in above we glued the array value with one space and make a string in returns


join() function is can convert the array to string in PHP.


$array=array("array",,"is""string","now");
echo implode(" ",$array); // it print array is string now


join("first argument is glue","second argument must be array ")

so in above we glued the array value with one space and make a string in returns with join() function in PHP

join() function is alias of the implode() function in PHP


if you want to convert array to JSON string .

json_encode() function will encode array to JSON, JSON is one type of string which formatted so it can convert JSON string to array again.

$response=array("stauts"=>"1");
echo json_encode($response);


JSON format is used to information exchange between server to server or server to client
Server Ajax response will be sent back to the browser in the format of JSON
Post Answer