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',''])); 

online demo


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -