/i am assuming that you already have something like
this. so that the current playing board is a matrix /
$board = array(
'row1' -> array();
'row2' -> array();
'row3' -> array();
);
There are 4 ways that someone can win.
1) they own a row
2) they own a column
3) they own diagnal going right
4) they own a diagnal going left
I'm not sure why you want this logic in a nested loop I would doo it like so.
function who_won($board);
//does someone own a row
for($i=0;$i<3;$ii++) {
if($board[$i][0] == $board[$i][1] == $board[$i][2]) {
return($board[$i][0]);
} //end if
} //end row check
//does someone own a column
for($i=0;$i<3;$ii++) {
if($board[0][$i] == $board[1][$i] == $board[2][$i]) {
return($board[0][$i]);
} //end if
} //end column check
//does soemone own the left diagnal
if($board[0][0] == $board[1][1] == $board[1][2]) {
retrun $board[0][0];
} //end if
//does someone own the right diagnoal
if($board[0][2] == $board[1][1] == $board[2][0]) {
return $board[0][2];
}
} //end who_won
This would be very complex with nested loops like you're asking for but it becomes trivial when done like above. I would however make sure that you don't execute this until the 5th turn has taken place because you know that no one has one before then.