note 102212 modified in function.parse-str by danbrown

From: Date: Thu, 03 Feb 2011 14:37:26 +0000
Subject: note 102212 modified in function.parse-str by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-176641@lists.php.net to get a copy of this message
I wrote an array to string function that works recursively and works with an n-dimensional array turning it into a parsable string for parse_str. <?php function queryString($params, $name=null) { $ret = ""; foreach($params as $key=>$val) { if(is_array($val)) { if($name==null) $ret .= queryString($val, $key); else $ret .= queryString($val, $name."[$key]"); } else { if($name!=null) $ret.=$name."[$key]"."=$val&"; else $ret.= "$key=$val&"; } } return $ret; } ?> --was-- I had a problem with the above array to string function, so I wrote one that works recursively and works with an n-dimensional array turning it into a parsable string for parse_str. function queryString($params, $name=null) { $ret = ""; foreach($params as $key=>$val) { if(is_array($val)) { if($name==null) $ret .= queryString($val, $key); else $ret .= queryString($val, $name."[$key]"); } else { if($name!=null) $ret.=$name."[$key]"."=$val&"; else $ret.= "$key=$val&"; } } return $ret; } http://php.net/manual/en/function.parse-str.php

« previous php.notes (#176641) next »