-2

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]]
epool
  • 1
  • 1

1 Answers1

0

You can use array_chunk

$matrix = array(1, 2, 1,1, 2, 1,1, 1, 1);
$res = array_chunk($matrix,3);
print_r($res);

Live working example

Rakesh Jakhar
  • 6,380
  • 2
  • 11
  • 20