function check_matrices($rows, $cols, $matrix) {
suppose $rows=0;
in this case will be NO LOOP
for( $i = 0; $i < $rows; ......
i = 0, and to loop is required $i < $rows;
Is 0 less than 0 ... NO!
In this case function will return return (1) ... true
You have written a function, where the exception from (1) is tested.
And the true state is set a normal return.
Maybe you should try the other, oposite approach.
======================================
Sometimes, if not most times, is better to CHECK for SCORE.
Take a game of normal European Football.
We have 1 judge, to decide if is GOAAAALLL, or not.
In a game of footbal normal result is like 2-1.
Many attempts will fail to make goal. Shots will not even come near Goal-Keeper.
Best method for judge(s) here is:
- nothing is goal
- until can be proven be a goal
Test goal.
1. set $result = false
2. has ball crossed line between goal sticks? if so then $result=true
3. return $result
=========================
Test if I was paid or not. (a bad method)
1. set $result= true
2. Test all ways and cases NOT TO PAY ME. if such case $result=false
3. return $result
Test if I was paid or not. (correct better method)
1. set $result= false
2. Did I get the money. if such case $result=true
3. return $result
regars 🙂
halojoy