3v4l.org

run code in 300+ PHP versions simultaneously
<?php $master_array = array(1, 2, 3, 4, 5, 6); $n = 2; // This is the number of columns / arrays $pattern_array = array(); $meta_array = array(); for ($i=1, $z=2*n; $i <= $n; ++$i) { $pattern_array[$i] = $i; $pattern_array[$z-i] = $i; $meta_array[] = array(); } foreach ($master_array as $i => $element) { $pattern_index = $i % $z; $meta_index = $pattern_array[$pattern_index] - 1; $meta_array[$meta_index][] = $element; } print_r($meta_array);
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.7
Fatal error: Uncaught Error: Undefined constant "n" in /in/cfWTn:8 Stack trace: #0 {main} thrown in /in/cfWTn on line 8
Process exited with code 255.
Output for 7.2.0 - 7.2.33, 7.3.12 - 7.3.33, 7.4.0 - 7.4.33
Warning: Use of undefined constant n - assumed 'n' (this will throw an Error in a future version of PHP) in /in/cfWTn on line 8 Warning: A non-numeric value encountered in /in/cfWTn on line 8 Warning: Use of undefined constant i - assumed 'i' (this will throw an Error in a future version of PHP) in /in/cfWTn on line 10 Warning: A non-numeric value encountered in /in/cfWTn on line 10 Warning: Use of undefined constant i - assumed 'i' (this will throw an Error in a future version of PHP) in /in/cfWTn on line 10 Warning: A non-numeric value encountered in /in/cfWTn on line 10 Fatal error: Uncaught DivisionByZeroError: Modulo by zero in /in/cfWTn:16 Stack trace: #0 {main} thrown in /in/cfWTn on line 16
Process exited with code 255.
Output for 7.1.0 - 7.1.20
Notice: Use of undefined constant n - assumed 'n' in /in/cfWTn on line 8 Warning: A non-numeric value encountered in /in/cfWTn on line 8 Notice: Use of undefined constant i - assumed 'i' in /in/cfWTn on line 10 Warning: A non-numeric value encountered in /in/cfWTn on line 10 Notice: Use of undefined constant i - assumed 'i' in /in/cfWTn on line 10 Warning: A non-numeric value encountered in /in/cfWTn on line 10 Fatal error: Uncaught DivisionByZeroError: Modulo by zero in /in/cfWTn:16 Stack trace: #0 {main} thrown in /in/cfWTn on line 16
Process exited with code 255.
Output for 7.0.0 - 7.0.20
Notice: Use of undefined constant n - assumed 'n' in /in/cfWTn on line 8 Notice: Use of undefined constant i - assumed 'i' in /in/cfWTn on line 10 Notice: Use of undefined constant i - assumed 'i' in /in/cfWTn on line 10 Fatal error: Uncaught DivisionByZeroError: Modulo by zero in /in/cfWTn:16 Stack trace: #0 {main} thrown in /in/cfWTn on line 16
Process exited with code 255.
Output for 4.4.5 - 4.4.9, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.24 - 5.5.35, 5.6.7 - 5.6.28
Notice: Use of undefined constant n - assumed 'n' in /in/cfWTn on line 8 Notice: Use of undefined constant i - assumed 'i' in /in/cfWTn on line 10 Notice: Use of undefined constant i - assumed 'i' in /in/cfWTn on line 10 Warning: Division by zero in /in/cfWTn on line 16 Warning: Division by zero in /in/cfWTn on line 16 Warning: Division by zero in /in/cfWTn on line 16 Warning: Division by zero in /in/cfWTn on line 16 Warning: Division by zero in /in/cfWTn on line 16 Warning: Division by zero in /in/cfWTn on line 16 Array ( [0] => Array ( ) [1] => Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 ) )
Output for 4.3.0 - 4.3.11, 4.4.0 - 4.4.4, 5.0.0 - 5.0.5, 5.1.0 - 5.1.6
Notice: Use of undefined constant n - assumed 'n' in /in/cfWTn on line 8 Notice: Use of undefined constant i - assumed 'i' in /in/cfWTn on line 10 Notice: Use of undefined constant i - assumed 'i' in /in/cfWTn on line 10 Array ( [0] => Array ( ) [1] => Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 ) )

preferences:
202.46 ms | 403 KiB | 316 Q