PHP Multidimensional Array

Asked

Viewed 156 times

2

Well I’ve bonded for making the inputs of matriz in 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 php Exercises-chapter03 exercise06.php on line 30

the file extension is .php and in the Ubuntu does not display this error someone knows because?

  • It is because you must have "hidden" errors, try adding these two lines: error_reporting(-1);&#xA;ini_set('display_errors', 'On'); at the front lines of the file

  • 1

    But the error happens because you are treating your variables as an array, put only: '....Matriz".$I.$J."'...

  • How is the structure of this print??

1 answer

4


The error is due to the use of the brackets, and the concatenation. Try the following form:

 <?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."' />";
   }
}


?>
  • Man was the problem anyway, through this line of reasoning I already tidied up the loop that was taking the data with $_GET[]. Thanks for the help.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.