How to create comma separated list from an array in PHP


The comma separated list can be created by using implode() function. The implode() is a builtin function in PHP and is used to join the elements of an array.

Return Type: The return type of implode() function is string. It will return the joined string formed from the elements of array.

  string implode( separator, array )

Example-1

<?php 
  
/* Declare an array and initialize it */
$Array = array( "GFG1", "GFG2", "GFG3" ); 
  
/* Display the array elements */
print_r($Array); 
  
/* Use implode() function to join */
// comma in the array 
$List = implode(', ', $Array); 
  
/* Display the comma separated list */
print_r($List); 
  
?> 

Example-2

<?php 
  
/* Declare an array and initialize it */
$Array = array(0, 1, 2, 3, 4, 5, 6, 7); 
  
/* Display the array elements */
print_r($Array); 
  
/* Use implode() function to join */
/* comma in the array */
$List = implode(', ', $Array); 
  
/* Display the comma separated list */
print_r($List); 
  
?> 


Fatal error: Cannot redeclare validate_input() (previously declared in /www/wwwroot/studentstutorial.com/demo/conn/conn.php:36) in /www/wwwroot/studentstutorial.com/demo/conn/conn.php on line 36