note 52871 added to function.implode

From: Date: Mon, 16 May 2005 08:29:28 +0000
Subject: note 52871 added to function.implode
Groups: php.notes 
Request: Send a blank email to php-notes+get-89480@lists.php.net to get a copy of this message
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); } ---- Manual Page -- http://www.php.net/manual/en/function.implode.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+52871 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+52871&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+52871&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+52871&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+52871&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+52871&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+52871&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#89480) next »