Re: simplify statement

From: Date: Mon, 05 Aug 2002 23:00:17 +0000
Subject: Re: simplify statement
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-111271@lists.php.net to get a copy of this message
$i=0; foreach($row as $val) { if ($val != 0) $i++; } $row is your array. Not sure what's in this array or how/where it's defined, but, the above will cycle through every value in the $row array comparing it to zero. Monty > From: jim@jimlong.net (Jim Long) > Organization: Jim Long Network/MDO/Music/Web > Reply-To: jim@jimlong.net > Newsgroups: php.general > Date: Mon, 05 Aug 2002 12:03:15 -0600 > To: php <php-general@lists.php.net> > Subject: simplify statement > > Anyone know how to simplify this statment: > > $i=0; > $s1=$row[s1]; > if ($s1!= 0){ > $i++; > } > $s2=$row[s2]; > if ($s2!= 0){ > $i++; > } > $s3=$row[s3]; > if ($s3!= 0){ > $i++; > } > $s4=$row[s4]; > if ($s4!= 0){ > $i++; > } > $s5=$row[s5]; > if ($s5!= 0){ > $i++; > } > $s6=$row[s6]; > if ($s6!= 0){ > $i++; > } > $s7=$row[s7]; > if ($s7!= 0){ > $i++; > } > $s8=$row[s8]; > if ($s8!= 0){ > $i++; > } > $s9=$row[s9]; > if ($s9!= 0){ > $i++; > } > $s10=$row[s10]; > if ($s10!= 0){ > $i++; > } > $s11=$row[s11]; > if ($s11!= 0){ > $i++; > } > $s12=$row[s12]; > if ($s12!= 0){ > $i++; > } > $s13=$row[s13]; > if ($s13!= 0){ > $i++; > } > $s14=$row[s14]; > if ($s14!= 0){ > $i++; > } > $s15=$row[s15]; > if ($s15!= 0){ > $i++; > } > > Thanks In Advance, > Jim Long

« previous php.general (#111271) next »