I was working on PHP. This is a crossword game. The code for the board is below:
$crossword = array(
array("+", "-", "-", "-", "-", "-", "-", "-", "-", "+"),
array("+", "-", "+", "+", "+", "+", "+", "+", "+", "+"),
array("+", "-", "-", "-", "-", "-", "-", "+", "+", "+"),
array("+", "-", "+", "+", "+", "+", "+", "+", "+", "+"),
array("-", "-", "-", "+", "+", "+", "+", "+", "+", "+"),
array("+", "-", "+", "+", "+", "+", "+", "+", "+", "+"),
array("+", "+", "+", "+", "+", "+", "+", "+", "+", "+"),
array("+", "+", "+", "+", "+", "+", "+", "+", "+", "+"),
array("+", "+", "+", "+", "+", "+", "+", "+", "+", "+"),
array("+", "+", "+", "+", "+", "+", "+", "+", "+", "+")
);
$boardLen = count($crossword);
$words = "pakistan;punjab;uae";
echo "<table>";
for ($row = 0; $row < $boardLen; $row++) {
echo "<tr>";
for ($col = 0; $col < $boardLen; $col++) {
echo "<td style = 'padding : 5px'>" . "<bold>" . $crossword[$row][$col] . "</bold>" . "</td>";
}
echo "</tr>";
}
echo "</table>";
echo $words."<br>";
$wordArr = explode(";",$words);
Here there is an associative array in which I made a crossword board. The places where - is to be replaced by the words which are at first declared in $words
and then they are converted into array. Now I am not getting the point of how to compare the values of $wordArr
array with the crossword associative array elements that have - and replace them with that word if the length is equal to it. I need guidance on how to compare the values and replace them as I am new to php,