Re: count() multidimensional array

From: Date: Sat, 19 May 2001 19:49:07 +0000
Subject: Re: count() multidimensional array
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-53543@lists.php.net to get a copy of this message
can't say for sure, but a good guess is some problems with undefined vars. try using fforeach insted, its alot simpler. <?php foreach($check as $j_pos => $j_val) foreach($check[$j_pos] as $i_pos => $i_val) $message .= "{$pre[$j_pos][$i_pos]} {$post[$j_pos][$i_pos]} {$name[$j_pos][$i_pos]} {$city[$j_pos][$i_pos]} {$state[$j_pos][$i_pos]} \n"; ?> <input type='checkbox' name='check[0][0]' value='1' checked> <input type='checkbox' name='check[0][1]' value='1'> <input type='checkbox' name='check[1][0]' value='1' checked> <input type='checkbox' name='check[1][1]' value='1' checked> <input type='checkbox' name='check[2][0]' value='1'> <input type='checkbox' name='check[2][1]' value='1'> <input type='checkbox' name='check[3][0]' value='1'> <input type='checkbox' name='check[3][1]' value='1' checked> ok, now we have an example, $check[0][0] $check[1][0] $check[1][1] $check[3][1] are set, the others are not. you can see why 'for($c = 0; $c < count($check); $c++)' will not work. foreach simplifies things alot. you also do not need to check 'if ($check[$j][$i] == 1)' becase if it is set at all, then it 'had' to be checked. Is this what you were looking for ? -- Chris Lee lee@mediawaveonline.com ""Dean Martin"" <dlmartin@cvn.net> wrote in message news:NEBBJLLDMLCJHBJBAMMGEEMADGAA.dlmartin@cvn.net... > I have a multidimensional array being created by a form. Most fields are > pre-populated with a few that people can add to the list. There is a box > beside each row that they can check whether that item is in or not. > > My code to list only the rows that were checked is this.. > > for ($j=1 ; $j=5; $j++) > { > for ($i=0 ; $i<count($check[$j]) ; $i++) > { > if ($check[$j][$i] == "1")//was boxed checked? > { > $message .= "$pre[$j][$i]. .$post[$j][$i]. .$name[$j][$i]. > .$city[$j][$i]. .$state[$j][$i]\n"; > } > } > } > > This code is creating an endless loop and times out the server with memory > overruns. > > What am I missing? > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.general (#53543) next »