note 25811 added to function.implode

From: Date: Mon, 07 Oct 2002 15:39:39 +0000
Subject: note 25811 added to function.implode
Groups: php.notes 
Request: Send a blank email to php-notes+get-37747@lists.php.net to get a copy of this message
'Implode' does not implodes recursively... It might quite useful implode recursively when you get a many Arrays values with keys that replaces themselves as: http://server/file.php?arg[1]=123&arg[2]=312&arg[3]=543&arg[2]=abc If you build this URL progressively it would a great a idea that the newest value indeed took the place of any older ones, thus: http://server/file.php?arg[1]=123&arg[3]=543&arg[2]=abc would be a better option; If one uses $_SERVER['REQUEST_URI'], this sanitation would not happen, the URL string would be greater and greater everytime. With implode_r (see below) it becomes easier to build a "sanitised" URL, the one that less likely will overflow the browser. $URL = $_SERVER['PHP_SELF']; $tmp = implode_r("&", $_REQUEST); /* So as to allow to get ANY VALUE (G/P) from the Browser... */ $URL .= "?".$tmp; /* implode_r */ function implode_r($glue, $array, $array_name = NULL){ while(list($key,$value) = @each($array)) if(is_array($value)) $return[] = implode_r($glue, $value, (string) $key); else if($array_name != NULL) $return[] = $array_name."[".(string) $key."]=".$value; else $return[] = $key."=".$value; return(implode($glue, $return)); } sorry I couldn't format the code. -- http://www.php.net/manual/en/function.implode.php http://master.php.net/manage/user-notes.php?action=edit+25811 http://master.php.net/manage/user-notes.php?action=delete+25811 http://master.php.net/manage/user-notes.php?action=reject+25811

« previous php.notes (#37747) next »