title: how to filter the array value based on sort array before foreach loop
body: <pre><code>productid    Qty    SupplierId 
  M0001        -      S0001
  M0002        -      S0002
  M0001        -      S0001
  M0002        -      S0002
  
  Quantity is an input. manually given by user
  
  
  $data = json_decode(file_get_contents("php://input"));
  $Product=$data-&gt;Product;
  $quantity=$data-&gt;quantity;
  $suppliername=$data-&gt;suppliername;
  
  sort($suppliername); //S0001,S0001,S0002,S0002
  
              foreach($suppliername as $index =&gt; $value)
              {   
                  $ProductArr = $Product[$index];
                  $QtyhArr = $quantity[$index];
                  $SupplierArr = $suppliername[$index];
  
                  $qry_resArr = $conn-&gt;prepare("INSERT INTO Table(Supplier,Product,Qty) VALUES (?,?,?)"); 
                  $qry_resArr-&gt;execute(array($SupplierArr,$ProductArr,$QtyhArr));
              }
  </code></pre>
  
  <p>how to filter the array value based on sort array before foreach loop. I need to pass the product,qty value based on the sorted array. how to do this?. Thanks you</p>
  
  <pre><code>Expected result: I need to pass into query below format
  S0001,M0001,300
  S0001,M0001,70
  S0002,M0002,150
  S0002,M0002,100
  </code></pre>