How to Convert Array to String in PHP?

In this blog, we will be going to convert an array to a string in PHP. This is going to be very simple and easy. We will be using implode() function in PHP to convert the array to a string.


Let's start with examples,


Convert Array of Strings to String in PHP


Code:


<?php

  

$users = ["Rahul", "Karan", "Yuvraj", "Anuj"];

  

$string = implode(', ', $users);

  

print_r($array);



Output:


Rahul, Karan, Yuvraj, Anuj



Convert Array of Numbers to String in PHP



Code:


<?php
  
$myArray = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
  
$string = implode(',', $myArray);
  
print_r($array);


Output:


0,1,2,3,4,5,6,7,8,9


I hope this will help you in your projects. If you have any doubt, let me know in the comments.