3v4l.org

run code in 300+ PHP versions simultaneously
<?php $competitors = [1, 2, 3, 4, 5 , 6, 7, 8]; $rounds = log( count( $competitors ), 2 ) + 1; // round one for( $i = 0; $i < log( count( $competitors ), 2 ); $i++ ) { $seeded = array( ); foreach( $competitors as $competitor ) { $splice = pow( 2, $i ); $seeded = array_merge( $seeded, array_splice( $competitors, 0, $splice ) ); $seeded = array_merge( $seeded, array_splice( $competitors, -$splice ) ); } $competitors = $seeded; } $events = array_chunk( $seeded, 2 ); if( $rounds > 2 ) { $round_index = count( $events ); // second round for( $i = 0; $i < count( $competitors ) / 2; $i++ ) { array_push( $events, array( array( 'from_event_index' => $i, 'from_event_rank' => 1 ), // rank 1 = winner array( 'from_event_index' => ++$i, 'from_event_rank' => 1 ) ) ); } $round_matchups = array( ); for( $i = 0; $i < count( $competitors ) / 2; $i++ ) { array_push( $round_matchups, array( array( 'from_event_index' => $i, 'from_event_rank' => 2 ), // rank 2 = loser array( 'from_event_index' => ++$i, 'from_event_rank' => 2 ) ) ); } $events = array_merge( $events, $round_matchups ); for( $i = 0; $i < count( $round_matchups ); $i++ ) { array_push( $events, array( array( 'from_event_index' => $i + count( $competitors ) / 2, 'from_event_rank' => 2 ), array( 'from_event_index' => $i + count( $competitors ) / 2 + count( $competitors ) / 2 / 2, 'from_event_rank' => 1 ) ) ); } } if( $rounds > 3 ) { // subsequent rounds for( $i = 0; $i < $rounds - 3; $i++ ) { $round_events = pow( 2, $rounds - 3 - $i ); $total_events = count( $events ); for( $j = 0; $j < $round_events; $j++ ) { array_push( $events, array( array( 'from_event_index' => $j + $round_index, 'from_event_rank' => 1 ), array( 'from_event_index' => ++$j + $round_index, 'from_event_rank' => 1 ) ) ); } for( $j = 0; $j < $round_events; $j++ ) { array_push( $events, array( array( 'from_event_index' => $j + $round_index + $round_events * 2, 'from_event_rank' => 1 ), array( 'from_event_index' => ++$j + $round_index + $round_events * 2, 'from_event_rank' => 1 ) ) ); } for( $j = 0; $j < $round_events / 2; $j++ ) { array_push( $events, array( array( 'from_event_index' => $j + $total_events, 'from_event_rank' => 2 ), array( 'from_event_index' => $j + $total_events + $round_events / 2, 'from_event_rank' => 1 ) ) ); } $round_index = $total_events; } } if( $rounds > 1 ) { // finals array_push( $events, array( array( 'from_event_index' => count( $events ) - 3, 'from_event_rank' => 1 ), array( 'from_event_index' => count( $events ) - 1, 'from_event_rank' => 1 ) ) ); } var_dump($events);
Output for git.master, git.master_jit, rfc.property-hooks
array(14) { [0]=> array(2) { [0]=> int(1) [1]=> int(8) } [1]=> array(2) { [0]=> int(4) [1]=> int(5) } [2]=> array(2) { [0]=> int(2) [1]=> int(7) } [3]=> array(2) { [0]=> int(3) [1]=> int(6) } [4]=> array(2) { [0]=> array(2) { ["from_event_index"]=> int(0) ["from_event_rank"]=> int(1) } [1]=> array(2) { ["from_event_index"]=> int(1) ["from_event_rank"]=> int(1) } } [5]=> array(2) { [0]=> array(2) { ["from_event_index"]=> int(2) ["from_event_rank"]=> int(1) } [1]=> array(2) { ["from_event_index"]=> int(3) ["from_event_rank"]=> int(1) } } [6]=> array(2) { [0]=> array(2) { ["from_event_index"]=> int(0) ["from_event_rank"]=> int(2) } [1]=> array(2) { ["from_event_index"]=> int(1) ["from_event_rank"]=> int(2) } } [7]=> array(2) { [0]=> array(2) { ["from_event_index"]=> int(2) ["from_event_rank"]=> int(2) } [1]=> array(2) { ["from_event_index"]=> int(3) ["from_event_rank"]=> int(2) } } [8]=> array(2) { [0]=> array(2) { ["from_event_index"]=> int(4) ["from_event_rank"]=> int(2) } [1]=> array(2) { ["from_event_index"]=> int(6) ["from_event_rank"]=> int(1) } } [9]=> array(2) { [0]=> array(2) { ["from_event_index"]=> int(5) ["from_event_rank"]=> int(2) } [1]=> array(2) { ["from_event_index"]=> int(7) ["from_event_rank"]=> int(1) } } [10]=> array(2) { [0]=> array(2) { ["from_event_index"]=> int(4) ["from_event_rank"]=> int(1) } [1]=> array(2) { ["from_event_index"]=> int(5) ["from_event_rank"]=> int(1) } } [11]=> array(2) { [0]=> array(2) { ["from_event_index"]=> float(8) ["from_event_rank"]=> int(1) } [1]=> array(2) { ["from_event_index"]=> float(9) ["from_event_rank"]=> int(1) } } [12]=> array(2) { [0]=> array(2) { ["from_event_index"]=> int(10) ["from_event_rank"]=> int(2) } [1]=> array(2) { ["from_event_index"]=> float(11) ["from_event_rank"]=> int(1) } } [13]=> array(2) { [0]=> array(2) { ["from_event_index"]=> int(10) ["from_event_rank"]=> int(1) } [1]=> array(2) { ["from_event_index"]=> int(12) ["from_event_rank"]=> int(1) } } }

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:
36.44 ms | 409 KiB | 8 Q