'PHP create 2d empty array

I have 2 dimensions, such row=6 and col=5. The size can change.

How can I create an 2D empty array. Following approach is NOT what I am looking for, because it does not contains anything.

$arr = array(array());

How can I create an 2d array with dynamic size of "" values.

Many Thanks, BM



Solution 1:[1]

This is how you can create a 2d array with a dynamic size

$array = array();
foreach ($rows as $row){
  $array_values = array();
  // Add as much values you want to add
  array_push($array_values, '1');
  array_push($array_values, '2');

  array_push($array, $array_values);
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Suraj Sanwal