3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* Build the array */ $result = []; for($i=0;$i<4;$i++){ $result[] = [ 'id' => $i + 1, 'title' => 'task '.($i + 1), 'tech_user_id' => 1, 'dev_priority' => $i + 1 ]; } /* Build the array ends */ function reArrange(&$result,$id,$new_dev_priority){ $curr_index = array_search($id,array_column($result,"id"),true); $limit_index = array_search($new_dev_priority,array_column($result,"dev_priority"),true); $process_node = $result[$curr_index]; $curr_dev_priority = $process_node['dev_priority']; if($curr_dev_priority === $new_dev_priority) return; // return if same priority was assigned. $offset = $curr_dev_priority > $new_dev_priority ? -1 : 1; /* rearrange by relocating elements to a new location(this is a minimized push) */ while($curr_index != $limit_index){ $result[$curr_index] = $result[$curr_index + $offset]; $result[$curr_index]['dev_priority'] = $result[$curr_index]['dev_priority'] - $offset; $curr_index += $offset; } $process_node['dev_priority'] = $new_dev_priority; // assign new dev priority $result[$curr_index] = $process_node; } echo "Initial state:##########",PHP_EOL; print_r($result); reArrange($result,3,1); echo "Rearranged state:##########",PHP_EOL; print_r($result);
Output for git.master, git.master_jit, rfc.property-hooks
Initial state:########## Array ( [0] => Array ( [id] => 1 [title] => task 1 [tech_user_id] => 1 [dev_priority] => 1 ) [1] => Array ( [id] => 2 [title] => task 2 [tech_user_id] => 1 [dev_priority] => 2 ) [2] => Array ( [id] => 3 [title] => task 3 [tech_user_id] => 1 [dev_priority] => 3 ) [3] => Array ( [id] => 4 [title] => task 4 [tech_user_id] => 1 [dev_priority] => 4 ) ) Rearranged state:########## Array ( [0] => Array ( [id] => 3 [title] => task 3 [tech_user_id] => 1 [dev_priority] => 1 ) [1] => Array ( [id] => 1 [title] => task 1 [tech_user_id] => 1 [dev_priority] => 2 ) [2] => Array ( [id] => 2 [title] => task 2 [tech_user_id] => 1 [dev_priority] => 3 ) [3] => Array ( [id] => 4 [title] => task 4 [tech_user_id] => 1 [dev_priority] => 4 ) )

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:
53.87 ms | 404 KiB | 8 Q