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], ) ; function rearrange(&$arr, $n) { for ($i = 0; $i < $n; $i++) { $j = $i+1; if($arr[$i]['product_type'] =='manufacturer'){ if($j%4!= 0){ //echo $i; $temp = $arr[$i]; $arr[$i] = $arr[$i + 1]; $arr[$i + 1] = $temp; } else { if ($i==0 || $i==1 || $i==2) { $temp = $arr[$i]; $arr[$i] = $arr[$i + 1]; $arr[$i + 1] = $temp; } else { $temp = $arr[$i]; $arr[$i] = $temp; } } } else { $temp = $arr[$i]; $arr[$i] = $temp; } } return $arr; } $keys = array_keys ($arr1); $n = count ($keys); $arr = rearrange($arr1, $n); print_r($arr);
Output for git.master, git.master_jit, rfc.property-hooks
Array ( [0] => Array ( [product_type] => manufacturer [id] => 2 ) [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] => seller ) [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:
89.03 ms | 1543 KiB | 4 Q