title: how to get array element in jquery from php
body: <p>I want to send array from php to jquery using json. the array in received but I have a problem to take elements from array.</p>
  
  <p>I did this: </p>
  
  <pre><code>&lt;?php
      $result[0] = 1;
      $result[1] = 6;
      echo json_encode($result);
  ?&gt;
  
  &lt;script type="text/javascript"&gt;
  $("#saveOrder").click(function(){           
      var customerName = $('input#customerName').val();
      var param = {"customerName":customerName,"action":"addOrder"};
      $.ajax({
              url: "controllers/Order.controller.php",  
              type: "POST",     
              data: param,                
              cache: false,       
              success: function (result) {        
          alert("result"+result);
          $.each(result,function(i,elem){
              alert(i+"_"+elem); 
          });
  
          var suc = result[0];
          alert("suc"+suc);
          var orderId = result[1];
          alert("id"+orderId);
                  if (suc==1) {     
                      $('#resultMsg').text("success");  
  
                  } else {              
              $('#resultMsg').text("error");  
          }
              }       
          });
          });
  &lt;/script&gt;
  </code></pre>
  
  <p>when I iterate through array, it display strange elements!</p>
  
  <pre><code>first,second, third and forth 
         loops : display nothing
  fifth loop   : display [
  sixth loop   : display 1
  seventh loop : display ,
  eighth loop  : display 6
  ninth loop   : display ]
  </code></pre>
  
  <p>how can I get the elements?</p>