3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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 7.1.0
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.14
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.6.28, hhvm-3.12.0
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 hhvm-3.10.0

Process exited with code 153.
Output for 4.3.0 - 4.4.4, 5.0.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 ) )