Get all possible key and values from select
I'm trying to convert pages with <select><option> where I fetch name=""
and value="" in order to get the value. This data will be transferred to
"{$name}={$value}" for every <option value=""> found.
<select name="example">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
would give:
example=1
example=2
example=3
However, in my case there can be multiple <select>, so I need some logic
to take these values and create all possible combinations such as
example=1&second=1, example=1&second=2, example=2&second=1 and
example=2&second=2. Of course, thanks to http_build_query(), I would
prefer getting these as an array with 4 arrays with 2 same keys but
different values:
<select name="example">
<option value="1">1</option>
<option value="2">2</option>
</select>
<select name="second">
<option value="1">1</option>
<option value="2">2</option>
</select>
Would become:
array(array('example' => 1,
'second' => 1),
array('example' => 1,
'second' => 2),
array('example' => 2,
'second' => 1),
array('example' => 2,
'second' => 2))
What method in php would be more ideal to create these arrays? Only way I
can think of are several loops in each other.
No comments:
Post a Comment