title: How to add an array from the data attribute and id using javascript and combine them in array php?
body: <p>I just want to ask if how to merge this two array from all id value and data-rate value on my list order? there is too many ul li, so i need to get them all and store it into array.</p>
  
  <p>this is my code in javascript:</p>
  
  <pre><code>                var h = [];
  
                  $("ul.reorder-photos-list li").each(function() {  h.push($(this).attr('id').substr(9));  });
  
                  var x = [];
  
                  $("ul.reorder-photos-list li").each(function() {  x.push($(this).attr('data-rate').substr(9));  });
  
  
                  $.ajax({
                      type: "POST",
                      url: "order_update.php",
                      data: {
                          ids: " " + h + "",
                          rate: " " + x + ""
                          },
                      success: function(html) 
                      {
                          window.location.reload();
                          /*$("#reorder-helper").html( "Reorder Completed - Image reorder have been successfully completed. Please reload the page for testing the reorder." ).removeClass('light_box').addClass('notice notice_success');
                          $('.reorder_link').html('reorder photos');
                          $('.reorder_link').attr("id","");*/
                      }
                  });
  </code></pre>
  
  <p>and this is my html code:</p>
  
  <pre><code>&lt;li id="image_li_&lt;?php echo $row['id']; ?&gt;" class="ui-sortable-handle"&gt;
  &lt;input id="rate" type="text" value="&lt;?= $row['rate']?&gt;" data-rate="&lt;?php echo $row['rate']; ?&gt;" &gt;
  </code></pre>
  
  <p>and then in my order_update.php this is my code. </p>
  
  <pre><code>$idArray    = explode(",",$_POST['ids']);
  $rateArray  = explode(",",$_POST['rate']);
  
  $ids = array();
  foreach ($idArray as $id) {
      $ids[] = $id;
  }
  
  $rates = array();
  foreach ($rateArray as $rate) {
      $rates[] = $rate;
  }
  
  $n = 0;
  $orderArray = array();
  while( $n &lt;= count($idArray) )
  {
      $orderArray[] = array("id" =&gt; $ids[$n], "data" =&gt; $rates[$n]);
      $n++;
  }
  </code></pre>
  
  <p>and this is my insert query from orderArray</p>
  
  <pre><code>function updateOrder($orderArray){
          $count = 1;
          foreach ($orderArray as $array){
              $update = mysqli_query($this-&gt;connect,"UPDATE `test` SET `order` = $count, `rate`=$array[rate] WHERE id = $array[id]");
              $count ++;  
          }
          return true;
      }
  </code></pre>
  
  <p>hope someones helps me. :)thanks in advance!</p>