How to Create Comma Separated List from an Array in PHP? Last Updated : 18 Sep, 2024 Comments Improve Suggest changes Like Article Like Report 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.Syntax:string implode( separator, array )Return Type:The return type of implode() function is string. It will return the joined string formed from the elements of array. Example 1: This example adds comma separator to the array elements. php <?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); ?> OutputArray ( [0] => GFG1 [1] => GFG2 [2] => GFG3 ) GFG1, GFG2, GFG3 Example 2: php <?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); ?> OutputArray ( [0] => 0 [1] => 1 [2] => 2 [3] => 3 [4] => 4 [5] => 5 [6] => 6 [7] => 7 ) 0, 1, 2, 3, 4, 5, 6, 7 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. Comment More infoAdvertise with us Next Article How to Create Comma Separated List from an Array in PHP? P PranchalKatiyar Follow Improve Article Tags : Web Technologies PHP PHP Programs Similar Reads How to Create HTML List from Array in PHP? Given an array containing some items, the task is to create an HTML list from an array in PHP. An HTML list is a collection of items enclosed within <ul> (unordered list) or <ol> (ordered list) tags. Each item in the list is enclosed within <li> (list item) tags. This article explo 3 min read How to Create an Array of Given Size in PHP? This article will show you how to create an array of given size in PHP. PHP arrays are versatile data structures that can hold multiple values. Sometimes, it's necessary to create an array of a specific size, either filled with default values or left empty. Table of Content Using array_fill() Functi 3 min read How to Remove Multiple Elements from an Array in PHP? Given an array containing some elements, the task is to remove some elements from the array in PHP. Below are the approaches to remove multiple elements from an array in PHP:Table of ContentUsing array_diff() FunctionUsing array_filter() FunctionUsing a Loop and unset() FunctionUsing array_diff_key( 4 min read How to Replace an Element Inside Array in PHP ? Given an array containing some elements, the task is to replace an element inside the array in PHP. There are various methods to manipulate arrays, including replacing elements. Examples:Input: arr = [10, 20, 30, 40, 50], index_1 = 100Output: [10, 100, 30, 40, 50]Input: arr = ['GFG', 'Geeks', 'Hello 3 min read How to create an array for JSON using PHP? In this article, we will see how to create an array for the JSON in PHP, & will see its implementation through examples. Array: Arrays in PHP is a type of data structure that allows us to store multiple elements of similar data type under a single variable thereby saving us the effort of creatin 3 min read Like