3v4l.org

run code in 300+ PHP versions simultaneously
<?php $labels = array('Element1', 'Element2', 'Element3', 'Element4', 'Element5', 'Element6'); # Put them into pairs $pairs_array = array_chunk($labels, 2); # Use array_map with custom function function joinTwoStrings($one_pair) { return $one_pair[0] . ', ' . $one_pair[1]; } $pairs_array = array_map('joinTwoStrings', $pairs_array); echo implode(',' . PHP_EOL, $pairs_array);

preferences:
30.93 ms | 402 KiB | 5 Q