Created
November 29, 2011 22:11
-
-
Save JeffreyWay/1406801 to your computer and use it in GitHub Desktop.
Turn querystring into associative array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$querystring = 'first=jeff&last=way'; | |
$final = array(); | |
foreach( explode('&', $querystring) as $p ) { | |
list($key, $value) = explode('=', $p); | |
$final[$key] = $value; | |
} | |
// Test it | |
echo "<pre>"; | |
print_r($final); | |
echo "</pre>"; |
Hello Jeffrey. I think this solution is more proper. :)
$querystring = 'first=jeff&last=way';
parse_str( $querystring, $final );
// Test it
echo "<pre>";
print_r($final);
echo "</pre>";
It absolutely is. :) The guy who asked me couldn't use parse_str for some reason. (I think it turned out to be a typo or something)
Most likely it was typo, cause parse_str is supported since PHP4
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm sure there's a more "proper" solution, but this should work until then. :)