I am trying to build a game board 8x8 for a small game of battleship with game pieces in place (kind of like checkers) so i could move the pieces with MySQL the players can move freely in the board to go against each others battleships.
the pieces will be place in predetermined spaces while other space will be empty and be handle by mysql
$pieces = array(
//battleship 1 player 1
"b1" => '<img src="images/b1.jpg" width="100" height="100" alt="b1">',
//battleship 2 player2
"b2" => '<img src="images/b1.jpg" width="100" height="100" alt="b1">',
);
// 'es' represents empty squares
$board = array(
array('b1','es','b1','es','b1','es','b1','es'),
array('es','b1','es','b1','es','b1','es','b1'),
array('b1','es','b1','es','b1','es','b1','es'),
array('es','es','es','es','es','es','es','es'),
array('es','es','es','es','es','es','es','es'),
array('es','es','es','es','es','es','es','es'),
array('b2','es','b2','es','b2','es','b2','es'),
array('es','b2','es','b2','es','b2','es','b2'),
array('b2','es','b2','es','b2','es','b2','es')
);
I already have a loop to display the board what I'm asking is how do I place the ($piece -> $board) I know you can use the array_replace to place the elements of and array into another array, but I do not know how with multidimensional arrays.
I am also trying to use mysql for movement inside the board
array_replace
won't help you here, it works differently than you think. Best would bearray_map
but if you use PHP < 5.3 it is difficult to pass the$pieces
array to the callback. – Felix Kling Oct 24 '10 at 7:58