3v4l.org

run code in 300+ PHP versions simultaneously
<?php # Helper to simulate the while $posts = function() { static $posts = 20; $posts--; return $posts < 0 ?: $posts; }; $counter = 0; echo "Looping Posts".PHP_EOL; while( $posts() ) { $counter++; echo "Post: {$counter}".PHP_EOL; if( $counter % 4 == 1 ) { /* template A? */ echo ' (A)~~> Posts: 1, 5, 9, 13, 17, etc…'.PHP_EOL; } elseif( $counter % 4 == 2 ) { /* template B? */ echo ' (B)~~> Posts: 2, 6, 10, 14, 18, etc…'.PHP_EOL; } elseif( $counter % 4 == 3 ) { /* template C? */ echo ' (C)~~> Posts: 3, 7, 11, 15, 19, etc…'.PHP_EOL; } elseif( $counter % 4 == 0 ) { /* template D? */ echo ' (D)~~> Posts: 4, 8, 12, 16, 20, etc…'.PHP_EOL; } }
Output for 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 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.30, 8.0.0 - 8.0.22, 8.1.0 - 8.1.9
Looping Posts Post: 1 (A)~~> Posts: 1, 5, 9, 13, 17, etc… Post: 2 (B)~~> Posts: 2, 6, 10, 14, 18, etc… Post: 3 (C)~~> Posts: 3, 7, 11, 15, 19, etc… Post: 4 (D)~~> Posts: 4, 8, 12, 16, 20, etc… Post: 5 (A)~~> Posts: 1, 5, 9, 13, 17, etc… Post: 6 (B)~~> Posts: 2, 6, 10, 14, 18, etc… Post: 7 (C)~~> Posts: 3, 7, 11, 15, 19, etc… Post: 8 (D)~~> Posts: 4, 8, 12, 16, 20, etc… Post: 9 (A)~~> Posts: 1, 5, 9, 13, 17, etc… Post: 10 (B)~~> Posts: 2, 6, 10, 14, 18, etc… Post: 11 (C)~~> Posts: 3, 7, 11, 15, 19, etc… Post: 12 (D)~~> Posts: 4, 8, 12, 16, 20, etc… Post: 13 (A)~~> Posts: 1, 5, 9, 13, 17, etc… Post: 14 (B)~~> Posts: 2, 6, 10, 14, 18, etc… Post: 15 (C)~~> Posts: 3, 7, 11, 15, 19, etc… Post: 16 (D)~~> Posts: 4, 8, 12, 16, 20, etc… Post: 17 (A)~~> Posts: 1, 5, 9, 13, 17, etc… Post: 18 (B)~~> Posts: 2, 6, 10, 14, 18, etc… Post: 19 (C)~~> Posts: 3, 7, 11, 15, 19, etc…
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17
Parse error: syntax error, unexpected T_FUNCTION in /in/02bBO on line 4
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_FUNCTION in /in/02bBO on line 4
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/02bBO on line 4
Process exited with code 255.

preferences:
67.97 ms | 413 KiB | 5 Q