title: PHP multiple variable array output
body: <p>I have a simple query.</p>
  
  <p>I have an array, which has two variables, which I define this way:</p>
  
  <pre><code>$sArray[0]['Name'] = $sName;
  $sArray[0]['ID'] = $sID;
  </code></pre>
  
  <p>The above is in a loop which feeds the data for sName and sID. Example of the Data is:</p>
  
  <pre><code>Name: John Smith ID: 123
  Name: Sue Smith ID:234
  </code></pre>
  
  <p>I'd like to output the sName data in a multi Select HTML and store the ID as the value and Name as the option display. The code I have below so far only outputs the first entry in the list, so the looping is not right. So, please help. :)</p>
  
  <pre><code>  &lt;select class="form-select" multiple id="SelectName" name="name_list[]"&gt;        
    &lt;?php             
      $selectLength = count($sArray);
      for ($j=0 ; $j&lt;$selectLength ; $j++) {
      foreach ($sArray[$j] as $value) {           
      echo"&lt;option value=$value name='name_list[]'&gt;$value&lt;/option&gt;"?&gt;    
     &lt;?php 
          }
      } ?&gt;
   &lt;/select&gt;
  </code></pre>
  
  <p>Below is the dump of the array contents:</p>
  
  <pre><code>array(1) { [0]=&gt; array(2) { ["Name"]=&gt; string(3) "Sue" ["ID"]=&gt; string(3) "234" } } array(1) { [0]=&gt; array(2) { ["Name"]=&gt; string(4) "John" ["ID"]=&gt; string(3) "123" } }
  </code></pre>
  
  <p>Thanks in advance.</p>
  
  <p>UPDATE:
  As requested, below is the loop which populates the array. It basically reads an XML file which has Name and ID data and places it in the array.</p>
  
  <pre><code>$fetchdata = simplexml_load_string($xml);    
  foreach ($elm-&gt;res as $list) {
          $Team = $Agentlist-&gt;xpath('team[@name="Stock"]');
          if (count($Team) &gt;= 1) {
              $fName = (string)$list-&gt;fName;
              $ID = (string)$list-&gt;ID;
              $sArray[0]['Name'] = $fName;
              $sArray[0]['ID'] = $ID;
              var_dump($sArray);          
          }
      }
  </code></pre>