3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = ['a', 'b', 'c', 'd', 'e']; function customReverse($array) { $reversedArray = []; $count = count($array); for ($i = 0; $i < count($array); $i++) { $reversedArray[] = $i % 2 === 0 ? $array[$i / 2] : $array[$count - ($i / 2)]; } return $reversedArray; } print_r(customReverse($array));
Output for 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.26, 8.4.1 - 8.4.13
Deprecated: Implicit conversion from float 4.5 to int loses precision in /in/LjRJD on line 9 Deprecated: Implicit conversion from float 3.5 to int loses precision in /in/LjRJD on line 9 Array ( [0] => a [1] => e [2] => b [3] => d [4] => c )
Output for 7.1.25 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30
Array ( [0] => a [1] => e [2] => b [3] => d [4] => c )

preferences:
139.28 ms | 408 KiB | 5 Q