Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Many Thanks,
BM

>Solution :

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);
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading