3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = array("purchase_order_details_id"=>array( 0=>"POD1", 1=>"POD1", 2=>"POD2", ), "quantity_received"=>array( 0=>5, 1=>10, 2=>20 ) ); $pods = array_unique($arr["purchase_order_details_id"]); Foreach($pods as $pod){ $PO = array_intersect($arr["purchase_order_details_id"], [$pod]); $qt = array_intersect_key($arr["quantity_received"], $PO); $new[$pod] = ["purchase_order_details_id" => $PO, "quantity_received" => $qt]; } Var_dump($new); extract($new);

preferences:
24.06 ms | 408 KiB | 5 Q