Perl\'s join()
ignores (skips) empty array values; PHP\'s implode()
does not appear to.
Suppose I have an array:
$array = a
Try this:
if(isset($array)) $array = implode(",", (array)$array);
Try this:
$result = array();
foreach($array as $row) {
if ($row != '') {
array_push($result, $row);
}
}
implode('-', $result);
Based on what I can find, I'd say chances are, there isn't really any way to use a PHP built in for that. But you could probably do something along the lines of this:
function implode_skip_empty($glue,$arr) {
$ret = "";
$len = sizeof($arr);
for($i=0;$i<$len;$i++) {
$val = $arr[$i];
if($val == "") {
continue;
} else {
$ret .= $arr.($i+1==$len)?"":$glue;
}
}
return $ret;
}