note 52871 deleted from function.implode by hholzgra

From: Date: Thu, 02 Aug 2012 13:16:20 +0000
Subject: note 52871 deleted from function.implode by hholzgra
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-189722@lists.php.net to get a copy of this message
Note Submitter: killroy at g m a i l dot c o m ---- Here is another variation on Chris' function. I added a $skip_empty parameter. if it's set to TRUE the result string will not contain keys whose values are empty. Great for building query_strings. If the parameter is not given it behaves like the original function: $a='1'; $b=''; $c='3'; INPUT: implode_assoc('=','&',array('a'=>$a,'b'=>$b,'c'=>$c),true); OUTPUT: a=1&c=3 INPUT: implode_assoc('=','&',array('a'=>$a,'b'=>$b,'c'=>$c)); OUTPUT: a=1&b=&c=3 function implode_assoc($inner_glue,$outer_glue,$array,$skip_empty=false){ $output=array(); foreach($array as $key=>$item) if(!$skip_empty || $item){$output[]=$key.$inner_glue.$item;} return implode($outer_glue,$output); }

« previous php.notes (#189722) next »