Change language

How do I create a comma separated list from an array in PHP?

|
Syntax:
string implode (separator, array)
Return type:implode() function return type - line. It will return a concatenated string formed from array elements.Example 1.This example adds a comma separator to the array elements.  
// Declare an array and initialize its $Array = array ( "GFG1" , "GFG2" , "GFG3" );  
// Show array elements print_r ( $Array );  
// Use implode() function to join
// comma in array $List = implode ( ’,’ , $Array );  
// Display a comma-separated list print_r ( $List );  
?>
Exit:
Array ([ 0] = > GFG1 [1] = > GFG2 [2] = > GFG3) GFG1, GFG2, GFG3
Example 2:  
// Declare an array and initialize it $Array = array (0, 1, 2, 3, 4, 5, 6, 7);  
// Show array elements print_r ( $Array );  
// Use implode() function to join
// comma in array $List = implode ( ’,’ , $Array );  
// Display a comma-separated list print_r ( $List );  
?>
Exit:
Array ([ 0] = > 0 [1] = > 1 [2] = > 2 [3] = > 3 [4] = > 4 [5] = > 5 [6] = > 6 [7 ] = > 7) 0, 1, 2, 3, 4, 5, 6, 7
SO 1 data error