Friday, 23 January 2015

Concatenate Array elements for Human Reading - PHP

This Source code used to Concatenate the Array Elements.For Example: Array is to be Printed.. John,Mary and Ishmal
<?php

$array = array('John', 'Mary', 'Ishmal');
echo concatenate($array);

function concatenate($elements, $delimiter = ', ', $finalDelimiter = ' and ')
{
$lastElement = array_pop($elements);
return join($delimiter, $elements) . $finalDelimiter . $lastElement;
}
?>
 
O/P: John,Mary and Ishmal

0 comments:

Post a Comment