RE: [PHP] Question: Simpler loop

From: Date: Fri, 22 Oct 2004 15:40:29 +0000
Subject: RE: [PHP] Question: Simpler loop
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-200092@lists.php.net to get a copy of this message
Slightly simpler: foreach(...) { $count = 0; if ($skill != '') $count++; if ($skys[$key] != '') $count++; if ($slus[$key] != '') $count++; if $count < 3 echo 'Invalid'; else echo 'Valid'; } Graham > -----Original Message----- > From: Stuart Felenstein [mailto:stuart4m@yahoo.com] > Sent: 22 October 2004 15:34 > To: php-general@lists.php.net > Subject: [PHP] Question: Simpler loop > > > I have rows of input fields > Each row contains 3 fields. The user must fill out > the entire row (all 3 fields) for things to work > right. > > I want to generate an error in case they have only > filled in 1 or 2 of the boxes. > > Thinking I might use something like this: > > foreach($skills as $key => $skill) > > { > if ($skill != '' && $skys[$key] = '' && > $slus[$key] = '') > { > > }else if{ > if ($skill = '' && $skys[$key] != '' && > $slus[$key] = '') > > }else{ > if ($skill = '' && $skys[$key] = '' && $slus[$key] > != '') > > ..... above only takes into account that 1 of that 3 > has been filled in. I would need another set to take > into account if 2 of the 3 have been filled in. > > Is there a simpler way / shorter way to check > conditions to do this ? > > Stuart > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >

« previous php.general (#200092) next »