Re: nested if in a for statement

From: Date: Tue, 17 Dec 2002 21:21:46 +0000
Subject: Re: nested if in a for statement
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-128609@lists.php.net to get a copy of this message
---- snip ---- /* variables in array set earlier in script */ $userVars = array($nameFirst, $nameLast, $pass, $pass2, $auth, $dob_year, $dob_month, $dob_day); for ($i=0; $i <= count($userVars); $i++) {
            if (empty($userVars[$i])) {
                 echo "please enter all required info";
                 break;
                }
            }
--- snip ----
count($array) returns the number of items in the array. $array[$i] retreives the item at location $i, but remember, this location is ZERO-BASED. That means if we have an array of 10 items, the positions would be from 0 to 9. In the above code you have $i <= count($userVars) The problem is that when $i = count($userVars), $i has surpassed the position of the last time, thus causing it to return as being empty. -- Kyle Gibson admin(at)frozenonline.com http://www.frozenonline.com/

« previous php.general (#128609) next »