Jump to content

Passing array as param


allinurl

Recommended Posts

Are you trying to generate an URL from an array? In your example, you're using "param" as a name in the query string twice. That's impossible. If you want to 'convert' an array's keys and values into names and values in a query string, this'll do:

 

<?php
$url = 'http://url.com?';
$array = array('name' => 'Joe', 'age' => 23);
foreach ($array as $key => $val) {
$url .= "$key=$val&";
}
$url = substr($url, 0, -1);
echo $url;
// http://url.com?name=Joe&age=23
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.