I am a PHP newbie and I am learning PHP off a book but I can not display a two-dimensional array using echo variable. Every time I try it always throws back this error, Warning: Uninitialized string offset 2 in C:\xampp\htdocs\test1.php on line 19. As I said I do not know what this means I have searched but it still does not display. My code
<?php //test1.php
echo $lang[2]; //Displays Javascript not CSS reason above
$ttt = array(
array('x', '', 'o'),
array('o', 'o', ''),
array('x', 'o', '')
); //you can stack arrays like this
echo $ttt[0][1][2]; //displaying tick tack toe
?>
line 19 is echo $ttt[0][1][2]; //displaying tick tack toe
CodePudding user response:
Hi there This is only a double so don't need all three just use
echo $ttt[0][2];
If you want to echo out the whole Tic Tack Toe you will need to echo each value like this
echo "<table><tr><td>{$ttt[0][0]}</td><td>{$ttt[0][1]}</td><td>{$ttt[0][2]}</td></tr>
<tr><td>{$ttt[1][0]}</td><td>{$ttt[1][1]}</td><td>{$ttt[1][2]}</td></tr>
<tr><td>{$ttt[2][0]}</td><td>{$ttt[2][1]}</td><td>{$ttt[2][2]}</td></tr></table>"; //displaying tick tack toe
Don't forget in programing we start at 0