Note that there are some explanatory texts on larger screens.

plurals
  1. POGet all possible key and values from select
    text
    copied!<h2>Note: I'm not interested in how I can parse anything into HTML. I already know that. In this scenario I'm extracting the HTML from a site, and I try to find the best way to make an array of all the different keys and values multiple selects can produce.</h2> <p>I'm trying to convert pages with <code>&lt;select&gt;&lt;option&gt;</code> where I fetch <code>name=""</code> and <code>value=""</code> in order to get the value. This data will be transferred to an array:</p> <pre><code>&lt;select name="example"&gt; &lt;option value="1"&gt;1&lt;/option&gt; &lt;option value="2"&gt;2&lt;/option&gt; &lt;option value="3"&gt;3&lt;/option&gt; &lt;/select&gt; </code></pre> <p>would give:</p> <pre><code>array(array('example' =&gt; 1), array('example' =&gt; 2), array('example' =&gt; 3)) </code></pre> <p>However, in my case there can be multiple <code>&lt;select&gt;</code>, so I need some logic to take these values and create all possible combinations in that array. I wish to be getting these as an array with 4 arrays with 2 same keys but different values:</p> <pre><code>&lt;select name="example"&gt; &lt;option value="1"&gt;1&lt;/option&gt; &lt;option value="2"&gt;2&lt;/option&gt; &lt;/select&gt; &lt;select name="second"&gt; &lt;option value="1"&gt;1&lt;/option&gt; &lt;option value="2"&gt;2&lt;/option&gt; &lt;/select&gt; </code></pre> <p>Would become:</p> <pre><code>array(array('example' =&gt; 1, 'second' =&gt; 1), array('example' =&gt; 1, 'second' =&gt; 2), array('example' =&gt; 2, 'second' =&gt; 1), array('example' =&gt; 2, 'second' =&gt; 2)) </code></pre> <p>What method in php would be more ideal to create these arrays? Only way I can think of are several loops in each other. I want this solution to be scalable and work with as many <code>&lt;select&gt;</code> as possible.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload