I have array like below:
$matrix = array(1, 2, 1,1, 2, 1,1, 1, 1);
how can I get array like below?
//OUTPUT:
minesweeper(matrix) = [[1, 2, 1],
[2, 1, 1],
[1, 1, 1]]
I have array like below:
$matrix = array(1, 2, 1,1, 2, 1,1, 1, 1);
how can I get array like below?
//OUTPUT:
minesweeper(matrix) = [[1, 2, 1],
[2, 1, 1],
[1, 1, 1]]
You can use array_chunk
$matrix = array(1, 2, 1,1, 2, 1,1, 1, 1);
$res = array_chunk($matrix,3);
print_r($res);