I have some form fields that when a form is submitted creates an array within the $_POST, I needing to check the this array has atleast 4 keys, how can I check that? I have no idea
+1
A:
Use array_keys
and count
:
echo count(array_keys($_POST));
Or simply:
echo count($_POST);
because keys are same in number as items.
Sarfraz
2010-06-18 11:12:34
+2
A:
If your form look something like this:
<input type='text' name='data[]' value='' />
Then, all you have to do is:
echo count($_POST['data']);
silent
2010-06-18 11:19:52
Sounds closest to what he's actually asking: length of array within $_POST, rather than length of $_POST.
Adam Backstrom
2010-06-18 12:46:54
+1
A:
try:
<?php
if(count($_POST) >= 4):
//Do your stuff
else:
//Do your error stuff
endif;
If you want to check an array within $_POST as apose to $_POST itself use count($_POST['name_of_key_to_array_you_want_to_count'])
Luke
2010-06-18 11:24:56