Stack Exchange
Build form with associative array name
I need to build a form to output the below $filters array:
Array
(
    [0] => Array
        (
            [filterType] => hotelStar
            [filterValue] => 3
        )

    [1] => Array
        (
            [filterType] => hotelStar
            [filterValue] => 5
        )

    [2] => Array
        (
            [filterType] => hotelStar
            [filterValue] => 4
        )

    [3] => Array
        (
            [filterType] => resultLimit
            [filterValue] => 2000
        )

)

The form that i have is 
<form action="output.php" method="get">
<input type="radio" name="filterType[]" value="[hotelStar]3,4,5">
<input type="radio" name="filterType[]" value="[hotelStar]3">
<input type="radio" name="filterType[]" value="[hotelStar]4">
<input type="radio" name="filterType[]" value="[hotelStar]5">
<input type="hidden" name="filterType[]" value="[resultLimit]2000">
<button type="submit">Submit</button>
</form>

The output that i receive is :
Array
(
    [filterType] => Array
        (
            [0] => [hotelStar]3
            [1] => [hotelStar]4
            [2] => [hotelStar]5
            [3] => [resultLimit]2000
        )

)

But the output isnot the expected one. I have tried almost all posibilities, but i cant find the working one.

Show us your attempts!

Please post the output that you get although it's wrong.

The array index you want has to be part of the form fields name, not the value.

My attempt would be the following:
Name the items in your form normal, eg.
<form action="<?$_SERVER['PHP_SELF']?>" method="get">
<input type="radio" name="hotelStar3" value="3">
<input type="radio" name="hotelStar4" value="4">
<input type="radio" name="hotelStar5" value="5">
<input type="hidden" name="resultLimit" value="2000">
<button type="submit" name = "submit" >Submit</button>
</form>

In your output.php, assign the values to the array.
if(isset($_GET['submit'])){
  $filters = array(
    array('filterType' => 'hotelStars', 'filterValue' => $_GET['hotelStars3']),
    array('filterType' => 'hotelStars', 'filterValue' => $_GET['hotelStars4']),
    array('filterType' => 'hotelStars', 'filterValue' => $_GET['hotelStars5']),
    array('filterType' => 'resultLimit', 'filterValue' => $_GET['resultLimit']));
  print_r($filters);


@em0tic0n Sorry, forgot brackets. Here you go.
