note 25811 deleted from function.implode by hholzgra

From: Date: Thu, 02 Aug 2012 13:13:41 +0000
Subject: note 25811 deleted from function.implode by hholzgra
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-189713@lists.php.net to get a copy of this message
Note Submitter: ulderico at maber dot com dot br ---- '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.

« previous php.notes (#189713) next »