I know that it's not necessary to define variables and arrays before using them in PHP. But I'm facing 'Undefined Variable mat1' and 'Undefined Variable mat2' errors when I run the following code:
for($i=0;$i<3;$i++)
{
for($j=0;$j<3;$j++)
{
$ans[$i][$j] = 0;
for($k=0;$k<3;$k++)
{
$ans[$i][$j] = $ans[$i][$j] + $mat1[$i][$k]*$mat2[$k][$j];
}
}
}
var_dump($ans);
I tried to define them with following 2 lines:
$mat1=array(array());
$mat2=array(array());
But errors were changed to 'Undefined offset: ...' errors. Am I missing something in my code?!