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 Remove Last Element from an Array in PHP ? Removing the last element from an array is a common operation in PHP. There are several approaches to achieve this. In this article, we will explore different methods to remove the last element from an array.Table of ContentUsing array_pop() FunctionUsing array_slice() FunctionUsing unset() Function 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 Remove First Element from an Array in PHP? Given an Array, the task is to remove the first element from the array in PHP. There are three methods to remove the first element from an array, these are - using array_shift(), array_slice(), and unset() functions. Let's explore each method with detailed explanations and code examples.Table of Con 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 get the First Element of an Array in PHP? Accessing the first element of an array in PHP is a common task, whether they are indexed, associative, or multidimensional. PHP provides various methods to achieve this, including direct indexing, and built-in functions.Below are the approaches to get the first element of an array in PHP:Table of C 4 min read How to remove a key and its value from an associative array in PHP ? Given an associative array containing array elements the task is to remove a key and its value from the associative array. Examples: Input : array( "name" => "Anand", "roll"=> "1") Output : Array ( [roll] => 1 ) Input : array( "1" => "Add", "2" => "Multiply", "3" => "Divide") Outpu 2 min read How to Compare Two Arrays in PHP? Given two arrays i.e. Array1, and Array2, the task is to compare both arrays in PHP. The comparison checks for equality finds differences, or determines common elements. PHP offers several functions and methods to compare arrays effectively. Below are the approaches to compare two arrays in PHP: Tab 2 min read Like