I am trying to pass arryas in url using PHP
Asked
Active
Viewed 1,251 times
4 Answers
1
It will not work this way. Better solution would be to save values in session variable and fetch them on next page.

Rahul Chauhan
- 59
- 7
0
You could pass it as a series of GETs and then form an array after this?
e.g.
<?php
// URL = http://www.webservicex.net/globalweather.asmx/GetWeather?CityName=Ahmadabad&CountryName=India
$array = [];
foreach($_GET as $get)
{
$array[] = $get;
}
var_dump($array);
?>
Not sure if this is what you are after but it seems to be the only option that I can see (I'd love someone else to be able to do this fully using an array in the URI!)
Or, you could use a header relocation:
header("Location: http://www.webservicex.net/globalweather.asmx/GetWeather?CityName=Ahmadabad&CountryName=India");
Hope this helps

Can O' Spam
- 2,718
- 4
- 19
- 45
0
Try
echo $params = http_build_query($array1);
Output will be: CityName=Ahmadabad&CountryName=India
$client = 'http://www.webservicex.net/globalweather.asmx/GetWeather?' . $params;

Wizard
- 10,985
- 38
- 91
- 165
0
You can do by using this simpler way: http_build_query
Example: i got this from here: passing arrays as url parameter
$data = array(
1,
4,
'a' => 'b',
'c' => 'd'
);
$query = http_build_query(array('aParam' => $data));
that's it.. :)

Community
- 1
- 1

Amrinder Singh
- 5,300
- 12
- 46
- 88