title: Foreach iteration structure show
body: <p>I have some script with <code>foreach</code>, see  below, 
  my for each always show output 2 - 1 - 3 - 4 - etc from my json object, how to solve my problem,?</p>
  
  <pre><code>&lt;?php public function renderLayout3x3($data=array()){
      $output = "&lt;ul&gt;";
  
      foreach ($data as $key =&gt; $value) {
          if($value['posisi'] == '1'){
              $output .= "&lt;li&gt;&lt;ul&gt;
                                  &lt;li&gt;POS:".$value['posisi']."&lt;/li&gt;
                                  &lt;li&gt;HOSTNAME:".$value['hostname']."&lt;/li&gt;
                          &lt;/ul&gt;&lt;/li&gt;";
          }
          if($value['posisi'] == '2'){
              $output .= "&lt;li&gt;&lt;ul&gt;
                                  &lt;li&gt;POS:".$value['posisi']."&lt;/li&gt;
                                  &lt;li&gt;HOSTNAME:".$value['hostname']."&lt;/li&gt;
                          &lt;/ul&gt;&lt;/li&gt;";
          }
          if($value['posisi'] == '3'){
              $output .= "&lt;li&gt;&lt;ul&gt;
                                  &lt;li&gt;POS:".$value['posisi']."&lt;/li&gt;
                                  &lt;li&gt;HOSTNAME:".$value['hostname']."&lt;/li&gt;
                          &lt;/ul&gt;&lt;/li&gt;";
          }
  
          //for debug..
          print json_encode($value['posisi']);
          /*
          Output : "2","1","3","4","5","6","7","8","9"
          Why : 2 - 1 - 3 - etc, not 1 - 2 - 3 - etc 
          */
      }
      $output .= "&lt;/ul&gt;";
      return $output;
  }
  
  $json_data = '{"ch":"79",
                  "ipaddr":"172.16.11.100",
                  "hostname":"TMC-MALL01",
                  "posisi":"2",
                  "monitorid":"17",
                  "view_dimension":"2*2",
                  "input_ipaddr":""
              }{
                  "ch":"78",
                  "ipaddr":"172.16.11.99",
                  "hostname":"TMC-JSB01",
                  "posisi":"1",
                  "monitorid":"17",
                  "view_dimension":"2*2",
                  "input_ipaddr":""
              }{
                  "ch":"80",
                  "ipaddr":"172.16.11.101",
                  "hostname":"TMC-MALL02",
                  "posisi":"3",
                  "monitorid":"17",
                  "view_dimension":"2*2",
                  "input_ipaddr":""
              }{
                  "ch":"92",
                  "ipaddr":"172.16.11.106",
                  "hostname":"TMC-PALMA01",
                  "posisi":"4",
                  "monitorid":"17",
                  "view_dimension":"2*2",
                  "input_ipaddr":""
              }{
                  "ch":"93",
                  "ipaddr":"172.16.11.107",
                  "hostname":"TMC-PALMA02",
                  "posisi":"5",
                  "monitorid":"17",
                  "view_dimension":"2*2",
                  "input_ipaddr":""
              }{
                  "ch":"112",
                  "ipaddr":"172.16.11.129",
                  "hostname":"TMC-R.PRM01",
                  "posisi":"6",
                  "monitorid":"17",
                  "view_dimension":"2*2",
                  "input_ipaddr":""
              }{
                  "ch":"113",
                  "ipaddr":"172.16.11.130",
                  "hostname":"TMC-R.PRM03",
                  "posisi":"8",
                  "monitorid":"17",
                  "view_dimension":"2*2",
                  "input_ipaddr":""
              }{
                  "ch":"114",
                  "ipaddr":"172.16.11.131",
                  "hostname":"TMC-R.PRM02",
                  "posisi":"7",
                  "monitorid":"17",
                  "view_dimension":"2*2",
                  "input_ipaddr":""
              }{
                  "ch":"115",
                  "ipaddr":"172.16.11.132",
                  "hostname":"TMC-R.PRM04",
                  "posisi":"9",
                  "monitorid":"17",
                  "view_dimension":"2*2",
                  "input_ipaddr":""
              }';
  
  $render = renderLayout3x3($json_data);
  print $render; ?&gt;
  </code></pre>
  
  <p>output always : </p>
  
  <pre><code>Output : "2","1","3","4","5","6","7","8","9"
  </code></pre>
  
  <p>Why : 2 - 1 - 3 - etc, not 1 - 2 - 3 - etc </p>
  
  <p>this is other output :
  <a href="https://i.stack.imgur.com/VyJl3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VyJl3.png" alt="output iteration"></a> </p>