php - How can I avoid printing the separator when elements are empty in the join()? -
here code:-
echo join(',', ['','']);
as know, prints comma. want avoid that. because elements empty , comma doesn't make sense. comma should deleted in this:
echo join(',', ['sth','']); // expected result: sth
how can that?
just remove empty items of array. can using array_filter()
function. try this:
echo join(',', array_filter(['sth','']));
Comments
Post a Comment