超越PHP PHP动态 | 经典文章 | CLASS | 相关下载 | 常见问题 | FORUM | WIKI | 在线手册
Site search:    
<shufflesort>
Last updated: Fri, 22 Jun 2007

sizeof

sizeof -- count() 的别名

说明

本函数是 count() 别名。




add a note add a note User Contributed Notes
sizeof
gramo at skina dot com dot co
26-Mar-2003 01:48
[ Editor's Note: Unchecked boxes are not passed to the form action page at all.  Therefore if only two of the four checkboxes below are checked, only two will be passed to the action page and sizeof/count will return two. grammo's statement that the array contains NULL elements is incorrect. ]

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<--------

<shufflesort>
 Last updated: Fri, 22 Jun 2007
view source | feedback | send page | sitemap | aboutus   
Copyright ® 2002-2003 PHPE.NET. All rights reserved
Last updated:2002-11-22