3v4l.org

run code in 500+ PHP versions simultaneously
<?php $arr1 = array( 0 => ['product_type'=>'manufacturer','id'=>1], 1 => ['product_type'=>'manufacturer','id'=>2], 2 => ['product_type'=>'seller'], 3 => ['product_type'=>'seller'], 4 => ['product_type'=>'seller'], 5 => ['product_type'=>'seller'], 6 => ['product_type'=>'seller'], 7 => ['product_type'=>'manufacturer','id'=>3], ); $manuCounter = 0; $sellerCounter = 0; $result = []; foreach ($arr1 as $row) { if ($row['product_type'] === 'manufacturer') { $manuCounter += 4; $result[$manuCounter] = $row; } else { ++$sellerCounter; if (!($sellerCounter % 4)) { ++$sellerCounter; } $result[$sellerCounter] = $row; } } ksort($result); var_export(array_values($result));
Output for git.master, git.master_jit, rfc.property-hooks
array ( 0 => array ( 'product_type' => 'seller', ), 1 => array ( 'product_type' => 'seller', ), 2 => array ( 'product_type' => 'seller', ), 3 => array ( 'product_type' => 'manufacturer', 'id' => 1, ), 4 => array ( 'product_type' => 'seller', ), 5 => array ( 'product_type' => 'seller', ), 6 => array ( 'product_type' => 'manufacturer', 'id' => 2, ), 7 => array ( 'product_type' => 'manufacturer', 'id' => 3, ), )

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
104.51 ms | 1515 KiB | 4 Q