Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!
We spend hours scrolling social media and waste money on things we forget, but won’t spend 30 minutes a day earning certifications that can change our lives.
Master in DevOps, SRE, DevSecOps & MLOps by DevOps School!
Learn from Guru Rajesh Kumar and double your salary in just one year.

We have given an array and the task is to convert the array elements into a string. In this query, we are using two methods to convert an array to a string.
Method 1: Using implode() function: The implode() method is an inbuilt function in PHP and is used to join the elements of an array. The implode() method is an alias for PHP | join() function and works exactly same as that of join() function.
Syntax:
string implode($separator, $array)
Example:
<?php
// Declare an array
$arr = array("Welcome","to", "DevopforDevops",
"A", "Computer","Language","program");
// Converting array elements into
// strings using implode function
echo implode(" ",$arr);
?>
Output:
Welcome to DevopsforDevops A Computer Language Program
Method 2: Using json_encode() Function: The json_encode() function is an inbuilt function in PHP which is used to convert PHP array or object into JSON representation.
Syntax:
string json_encode( $value, $option, $depth )
Example:
<?php
// Declare multi-dimensional array
$value = array(
"name"=>"DFD",
array(
"email"=>"dce@dfd.com",
"mobile"=>"XXXXXXXXXX"
)
);
// Use json_encode() function
$json = json_encode($value);
// Display the output
echo($json);
?>
Output:
{"name":"DFD","0":{"email":"dce@dfd.com","mobile":"XXXXXXXXXX"}}