I'm sending multiple parameters to another page, and I am using http_build_query()
to do this. The following code:
$array = array();
if(!empty($_POST['modelcheck'])){
foreach($_POST['modelcheck'] as $selected){
$array[] = $selected;
}
}
$args = array
(
'pricefrom' => $fromval,
'priceto' => $toval,
'model' => $array
);
$params = http_build_query($args);
$cleanedParams = preg_replace('/%5B(\d+?)%5D/', '', $params);
header("Location: ../page2.php?" . $cleanedParams);
gives me a url:
page2.php?pricefrom=10000&priceto=60000&model=1&model=2
As you can see model is repeated multiple times, I would like the parameters following the first model
to be model2
, model3
.......etc.
I've tried putting it in a for loop:
for ($i=0; $i <count($array) ; $i++) {
$args = array
(
'pricefrom' => $fromval,
'priceto' => $toval,
'model'.$i => $array
);
}
but this just gives me :
page2.php?pricefrom=10000&priceto=60000&model1=1&model1=2