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)]);

preferences:
90.05 ms | 405 KiB | 5 Q