Skip to content
Related Articles

Related Articles

How to convert array to string in PHP ?

View Discussion
Improve Article
Save Article
Like Article
  • Difficulty Level : Basic
  • Last Updated : 31 Jul, 2021

We have given an array and the task is to convert the array elements into string. In this article, we are using two methods to convert array to 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.


string implode($separator, $array)



// Declare an array 
$arr = array("Welcome","to", "GeeksforGeeks"
    "A", "Computer","Science","Portal");  
// Converting array elements into
// strings using implode function
echo implode(" ",$arr);


Welcome to GeeksforGeeks A Computer Science Portal

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.

string json_encode( $value, $option, $depth )



// Declare multi-dimensional array 
$value = array
// Use json_encode() function 
$json = json_encode($value); 
// Display the output 



PHP is a server-side scripting language designed specifically for web development. You can learn PHP from the ground up by following this PHP Tutorial and PHP Examples.

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!