How can the implode function be used to list array elements with commas in PHP?

To list array elements with commas in PHP, you can use the implode function. This function takes an array as its first parameter and a string as its second parameter (optional) to specify the delimiter. It concatenates all the elements of the array into a single string separated by the specified delimiter. This is useful when you want to display array elements as a comma-separated list.

// Sample array
$array = array('apple', 'banana', 'orange');

// Using implode to list array elements with commas
echo implode(', ', $array);