Multidimensional Array PHP

2

Well, I have created loops to make the inputs of matriz into html with the following code.

for($I=0; $I<5;++$I){
   for($J=0;$J<3;++$J){
      print" Matriz A: <input class='_InpText2' type='text' name='Matriz".[$I][$J]."' />";
   }
}

for($I=0; $I<5;++$I){
   for($J=0;$J<3;++$J){
       echo " Matriz B: <input class='_InpText2' type='text' name='Matriz".[$I][$J]."' />";
   }
}

This code above in Windows reproduces the following error:

  

Notice: Undefined offset: 1 in   C: \ xampp \ htdocs \ php \ exercises-chapter03 \ exercise06.php on line 30

The file extension is .php and in Ubuntu does not display this error does anyone know why?

    
asked by anonymous 23.01.2017 / 14:15

1 answer

4

The error is due to the use of the brackets, and the concatenation. Please try the following:

 <?php

for($I=0; $I<5;++$I){
   for($J=0;$J<3;++$J){
      print" Matriz A: <input class='_InpText2' type='text' name='Matriz".$I.$J."' />";
   }
}

for($I=0; $I<5;++$I){
   for($J=0;$J<3;++$J){
       echo " Matriz B: <input class='_InpText2' type='text' name='Matriz".$I.$J."' />";
   }
}


?>
    
23.01.2017 / 14:19