3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr= array ( 'supplier_id' => 1, 'filter_name' => array ( 0 => 'product 1', 1 => 'Product 2', 2 => 'Product 3' ), 'quantity' => array ( 0 => 3, 1 => 10, 2 => 2 ), 'unit' => array ( 0 => 'pkts', 1 => 'ltrs', 2 => 'pkts' ), 'price' => Array ( 0 => 11, 1 => 100, 2 => 10 ), 'gross_amount' => Array ( 0 => 33, 1 => 1000, 2 => 20 ), 'vat' => array ( 0 => 0, 1 => 0, 2 => 0 ), 'net_amount' => array ( 0 => 33, 1 => 1000, 2 => 20 ), ); //echo "<pre>"; print_r($arr); $i = 0; $newArray = array(); do{ foreach($arr as $key=>$val){ if($key == 'supplier_id'){ $newArray[$key] = $val; }else{ $newArray[$i][$key] = $val[$i]; } } $i++; }while($i<3); echo "<pre>"; print_r($newArray);
Output for 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
<pre>Array ( [supplier_id] => 1 [0] => Array ( [filter_name] => product 1 [quantity] => 3 [unit] => pkts [price] => 11 [gross_amount] => 33 [vat] => 0 [net_amount] => 33 ) [1] => Array ( [filter_name] => Product 2 [quantity] => 10 [unit] => ltrs [price] => 100 [gross_amount] => 1000 [vat] => 0 [net_amount] => 1000 ) [2] => Array ( [filter_name] => Product 3 [quantity] => 2 [unit] => pkts [price] => 10 [gross_amount] => 20 [vat] => 0 [net_amount] => 20 ) )
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 <pre>Array ( [supplier_id] => 1 [0] => Array ( [filter_name] => product 1 [quantity] => 3 [unit] => pkts [price] => 11 [gross_amount] => 33 [vat] => 0 [net_amount] => 33 ) [1] => Array ( [filter_name] => Product 2 [quantity] => 10 [unit] => ltrs [price] => 100 [gross_amount] => 1000 [vat] => 0 [net_amount] => 1000 ) [2] => Array ( [filter_name] => Product 3 [quantity] => 2 [unit] => pkts [price] => 10 [gross_amount] => 20 [vat] => 0 [net_amount] => 20 ) )

preferences:
242.39 ms | 403 KiB | 291 Q