Skip to content

Instantly share code, notes, and snippets.

@JeffreyWay
Created November 29, 2011 22:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JeffreyWay/1406801 to your computer and use it in GitHub Desktop.
Save JeffreyWay/1406801 to your computer and use it in GitHub Desktop.
Turn querystring into associative array
$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>";
@JeffreyWay
Copy link
Author

I'm sure there's a more "proper" solution, but this should work until then. :)

@Mamaduka
Copy link

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>";

@JeffreyWay
Copy link
Author

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)

@Mamaduka
Copy link

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