cannot shuffle array declared in class.
it gives me: cannot access empty property. I want to display a chess board. using a 2D array. the code works fine if not used as functions in a class. I want to shuffle the array and display it.
private $board = array(array('k', 'k', 'b', 'q', 'k', 'b', 'k', 'r'),
array('p', 'p', 'p', 'p', 'p', 'p', 'p', 'p'),
array(' ', ' ', ' ', ' ', ' ',
' ', ' ', ' '),
array('p', 'p', 'p', 'p', 'p', 'p', 'p', 'p'),
array('r', 'k', 'b', 'q', 'k', 'b', 'k', 'r'));
public function produce()
{
shuffle($this->$board);
echo "<div id='inside'>";
for($yIndex = 0; $yIndex < count($board); $yIndex++)
{
echo "<div class='row'>";
for($xIndex = 0; $xIndex < count($board[$yIndex]); $xIndex++)
{
echo "<div class='column' data-square=$yIndex-$xIndex>
<div class=".$board[$yIndex][$xIndex]."></div></div>";
}
echo "</div>";
}
}}$a = new Display();$a->produce();
You have the syntax wrong, it should be
$this->boardinstead of$this->$board. The second form is accessing a variable property, as in