Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Consider switching your array to use key-value pairs instead of nested arrays. (Refer to the <a href="http://php.net/manual/en/language.types.array.php" rel="nofollow">array</a> documentation.) </p> <pre><code>$enquiry_choices = array( 'Complaint' =&gt; 'csm@examplecompany.co.za', 'Suggestion' =&gt; 'csm@examplecompany.co.za', 'Compliment' =&gt; 'csm@examplecompany.co.za', 'Locate a dealer/distributor' =&gt; 'sales@examplecompany.co.za', 'Technical support' =&gt; 'technical@examplecompany.co.za', 'Back orders' =&gt; 'backorders@examplecompany.co.za', 'Product enquiry' =&gt; 'sales@examplecompany.co.za', 'Catalog request' =&gt; 'sales@examplecompany.co.za', 'New customer enquiry' =&gt; 'sales@examplecompany.co.za', 'Existing customers - logon' =&gt; 'dealers@examplecompany.co.za', 'Existing customers - orders' =&gt; 'weborder@examplecompany.co.za', 'Web site problems' =&gt; 'webmaster@examplecompany.co.za', ); // Optional: Sort the choices by name ksort($enquiry_choices); </code></pre> <p>This makes it easy to get the e-mail address associated with the user's choice.</p> <pre><code>$enquiry = $_GET['enquiry']; $enquiry_email = (array_key_exists($enquiry, $enquiry_choices) ? $enquiry_choices[$enquiry] : false); </code></pre> <p>It is also simple to generate the HTML for the dropdown list. (Refer to the <a href="http://php.net/manual/en/control-structures.foreach.php" rel="nofollow">foreach</a> documentation.) Note that the code above that defines <code>$enquiry</code> must preceed the code below.</p> <pre><code>echo &lt;&lt;&lt;HTML &lt;div&gt; &lt;label for="enquiry"&gt;Enquiry:&lt;/label&gt; &lt;/div&gt; &lt;select name="enquiry" id="enquiry" class="select"&gt; HTML; foreach($enquiry_choices as $key =&gt; $value) { $selected = ($enquiry == $key ? ' selected="selected"' : ''); echo "&lt;option$selected&gt;$key&lt;/option&gt;"; } echo '&lt;/select&gt;'; </code></pre>
 

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