Although the answer has already been given but i think this one also suits your all requirements very well. It will work if there is a comma in starting,end or in between.I hope so :]
public function verywell[]
{
$string1='1,2,3,4,5,6,,,,,,,';
$string2=',,,,,,,,7,,9';
$string3='10,11,,,,,,,,12';
$arr1= explode[',', $string1];
$arr2= explode[',', $string2];
$arr3= explode[',', $string3];
$val= array_merge[$arr1,$arr2,$arr3];
foreach[$val as $key=>$value]
{
if[$value=='']
{
unset[$val[$key]];
}
}
echo implode[',',$val];
}
While on a chat with a friend who recently started learning PHP programming language, he ask me what is the difference between using a comma [,] and a dot [.] as a concatenator.
My answer to him was: for the record, comma isn’t a concatenator. it use for printing or rather echoing a list of variable, string and numbers similar to how it is used in English. While dot joins two strings together to make one longer string.
Take note: comma only work when using the echo language construct and you can’t return a comma delimited variable.
ExamplesLet’s see some code example.