Edit: Donβt miss Stefan's solution above, which uses the very handy http_build_query() function: https://stackoverflow.com/a/164648/
knittl is right on the shoot. However, there is an easier way to do this:
$url = 'http://example.com/index.php?'; $url .= 'aValues[]=' . implode('&aValues[]=', array_map('urlencode', $aValues));
If you want to do this with an associative array, try this instead:
PHP 5.3+ (lambda function)
$url = 'http://example.com/index.php?'; $url .= implode('&', array_map(function($key, $val) { return 'aValues[' . urlencode($key) . ']=' . urlencode($val); }, array_keys($aValues), $aValues) );
PHP <5.3 (callback)
function urlify($key, $val) { return 'aValues[' . urlencode($key) . ']=' . urlencode($val); } $url = 'http://example.com/index.php?'; $url .= implode('&', array_map('urlify', array_keys($aValues), $aValues));
Jordan Running Nov 19 '09 at 14:33 2009-11-19 14:33
source share