how to compare and replace the values in array in php

74 views Asked by At

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,

0

There are 0 answers