Snippets v2

Languages
My Snippets

Implode an Array only for non-empty values Login or Register to Bookmark this snippet

Description PHP

Implodes a string with only the pieces of an array that are not empty.

The Code Download
  1. function implodeSupplied($glue,$pieces){
  2.     if (is_array($pieces)){
  3.         $str = '';
  4.         foreach($pieces as $key => $val){
  5.             if (strlen($val) > 0){
  6.                 $str .= $val.$glue;
  7.             }
  8.         }
  9.         return trim($str,$glue);
  10.     } else {
  11.     return $pieces;
  12.     }
  13. }
Credits Contact JC

Added by JC on 13th January, 2008

Comments

There are no comments about this snippet.

Post Comment HTML is allowed

You must be registered and logged in to post a comment.

Login here to post a comment