note 30699 added to function.sizeof

From: Date: Wed, 26 Mar 2003 03:48:51 +0000
Subject: note 30699 added to function.sizeof
Groups: php.notes 
Request: Send a blank email to php-notes+get-45833@lists.php.net to get a copy of this message
When you have a php page receiving data from a form with an array like: --------8<----------------8<----------------8<-------- <FORM ACTION="receiver.php" METHOD=POST> <INPUT TYPE=CHECKBOX NAME="arreglo[0]">Thing #1 <INPUT TYPE=CHECKBOX NAME="arreglo[1]">Thing #2 <INPUT TYPE=CHECKBOX NAME="arreglo[2]">Thing #1 <INPUT TYPE=CHECKBOX NAME="arreglo[3]">Thing #4 <INPUT TYPE=SUBMIT> </FORM> --------8<----------------8<----------------8<-------- And you just pick Thing #2 and Thing #4 like: --------8<----------------8<----------------8<-------- [ ] Thing #1 [X] Thing #2 [ ] Thing #1 [X] Thing #4 [OK] --------8<----------------8<----------------8<-------- When you count the number of elements in arreglo {NULL, "on", NULL, "on"} you receive just a 2 for answer, because NULL counts as no element for the count function. These have huge importance when you generate the forwarding form with a database query and you need to know how many elements does the script generate. The only way to fix these problem is by adding a new element at the form in this way: --------8<----------------8<----------------8<--------<FORM ACTION="receiver.php" METHOD=POST> <INPUT TYPE=HIDDEN NAME="arreglo_size" VALUE="4"> <INPUT TYPE=CHECKBOX NAME="arreglo[0]">Thing #1 <INPUT TYPE=CHECKBOX NAME="arreglo[1]">Thing #2 <INPUT TYPE=CHECKBOX NAME="arreglo[2]">Thing #1 <INPUT TYPE=CHECKBOX NAME="arreglo[3]">Thing #4 <INPUT TYPE=SUBMIT> </FORM> --------8<----------------8<----------------8<-------- -- http://www.php.net/manual/en/function.sizeof.php http://master.php.net/manage/user-notes.php?action=edit+30699 http://master.php.net/manage/user-notes.php?action=delete+30699 http://master.php.net/manage/user-notes.php?action=reject+30699

« previous php.notes (#45833) next »