Suppose I have 2d array, where only some rows actually have some values in the columns, whereas other rows don't have anything.
For example: only rows 5 and 9 have some data, other rows are empty. Number of columns is fixed - 6
I have not declared any size for the 2D array.
I want to find all fields whose value is 10.
for ($t1=0; $t1 < count($array); $t1++) {
for ($t2=0; $t2 < 6; $t2++) {
if($array[$t1][$t2] == 10) {
// do something
}
}
}
Now this code won't work because count($array) will be 2, so it will never iterate for rows 5 and 9.
I also need to get the index at which I found a match.
How can I write code to make it work in this case?