I have homework to do this program in PHP, that take a matrix and the keywords, so it can find them in the matrix diagonally:

[![enter image description here](https://i.stack.imgur.com/UPizE.png)](https://i.stack.imgur.com/UPizE.png)

So this is how the first matrix looks, there are many with different keywords, here for instance keywords are "beef" and "pork". So I made a program for an input that looks like these 2 examples:

[![enter image description here](https://i.stack.imgur.com/Uhada.jpg)](https://i.stack.imgur.com/Uhada.jpg)[![enter image description here](https://i.stack.imgur.com/gLpFu.jpg)](https://i.stack.imgur.com/gLpFu.jpg)

There correct input for these two is here:

[![enter image description here](https://i.stack.imgur.com/HO3gl.jpg)](https://i.stack.imgur.com/HO3gl.jpg)
[![enter image description here](https://i.stack.imgur.com/7ASrz.jpg)](https://i.stack.imgur.com/7ASrz.jpg)

Here is my code that works only in the first case, I don't know how to make a loop that will make more and more conditions instead of writing down all these conditions with && in if statement.

Please give me some tips on how to do it:

```
<?PHP

$input_line = trim(fgets(STDIN));
$input_array = explode(" ",$input_line);

// get mojiban
$mojiban = array();
for($ix=0; $ix<$input_array[0];$ix++){
    $mojiban[] = str_split(trim(fgets(STDIN)));
}

//get words
    $words = array();
    for( $kx = 0; $kx < $input_array[1]; $kx++ ){
    $words[] = trim(fgets(STDIN));
}

////check verticales
//get word
    $wordCharArray = array();
for($dx=0; $dx < $input_array[1]; $dx++){
    $wordCharArray = str_split($words[$dx]);

//looping and checking

    for ( $line = 0; $line < $input_array[0] ; $line++) {
        for ( $column = 0; $column < $input_array[0] ; $column++ ){
           // for ($wordsNumber = 0; $wordsNumber < $input_array[1] ; $wordsNumber++){

                if ($mojiban[$line][$column] == $wordCharArray[0] && $mojiban[$line+1][$column+1] == $wordCharArray[1]) {
                    echo ($column+1)." ".($line+1)."\n";

            //}
        }
    }
}

```

Thanks in Advance!