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 How to create a string by joining the array elements using PHP ? We have given an array containing some array elements and the task is to join all the array elements to make a string. In order to do this task, we have the following methods in PHP:Table of ContentUsing implode() Method: Using join() MethodUsing array_reduce()Using a Foreach LoopUsing array_map() w 3 min read How to re-index an array in PHP? The re-index of an array can be done by using some inbuilt function together. These functions are: array_combine() Function: The array_combine() function is an inbuilt function in PHP which is used to combine two arrays and create a new array by using one array for keys and another array for values. 5 min read Get the First & Last Item from an Array in PHP We will get the first and last elements of an array in PHP. This can be particularly useful in scenarios like processing data, working with queues, or implementing specific algorithms. Below are the approaches to get the first and last items from an array in PHP: Table of Content Using Array Indexin 2 min read How to Convert Array to String in PHP? In PHP, Arrays are used to store multiple values in a single variable. However, sometimes we need to convert these arrays into strings:To display array data in a readable format.To join array items into a single sentence or list.To use the array data where only strings are accepted.To prepare data f 2 min read How to Convert Query String to an Array in PHP? In this article, we will see how to convert a query string to an array in PHP. The Query String is the part of the URL that starts after the question mark(?).Examples:Input: str = "company=GeeksforGeeks&address=Noida&mobile=9876543210"Output: Array ( [company] => GeeksforGeeks [ad 4 min read Like