3v4l.org

run code in 300+ PHP versions simultaneously
<?php $board = [ ['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i'], ]; /* $flatBoxes = []; $boxIndexes = [0, 3, 6]; $boardLength = count($board[0]); $boxRows = []; for($start = 0; $start < $boardLength; $start += 3) { for($row = 0; $row < $boardLength; $row += 1) { $boxWidth = 3; $boxRow = array_slice($board[$row], $start, $boxWidth); $boxRows[] = $boxRow; } } $boxesList = []; for($start = 0; $start < count($boxRows); $start += 3) { $end = 3; $box = array_slice($boxRows, $start, $end); $boxesList[] = $box; } $boxes = []; for($boxIndex = 0; $boxIndex < count($boxesList); $boxIndex += 1) { $boxList = $boxesList[$boxIndex]; $row = []; for($box = 0; $box < count($boxList); $box += 1) { $choosenBox = $boxList[$box]; for($index = 0; $index < count($choosenBox); $index += 1) { $digit = $choosenBox[$index]; array_push($row, $digit); } } array_push($boxes, $row); }*/ var_export([array_merge(...$board)]);
Output for 7.4.0 - 7.4.33, 8.0.1 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.26, 8.4.1 - 8.4.13
array ( 0 => array ( 0 => 'a', 1 => 'b', 2 => 'c', 3 => 'd', 4 => 'e', 5 => 'f', 6 => 'g', 7 => 'h', 8 => 'i', ), )

preferences:
119.4 ms | 407 KiB | 5 Q