Checking if multidimensional array is empty?


Posted on 16th Feb 2014 07:03 pm by admin

I have a for with multiple test input fields. Specifically the user submits multiple names and ages. The form is submitted using the POST method. Here is a code snippet:

Code:
<form action = {$_SERVER['PHP_SELF']} method = 'post' >

for($i=1; $i<=10; $i++){

<input type = 'text' name = 'name[]' size ='25' maxlength = '50' />
<input type = 'text' name = 'age[]' size ='25' maxlength = '50' />

}

<input type="submit" />

</form>

I want to check if the user clicks submits without entering values in the text fields.

I have tried this:

Code: if(empty($_POST['name']) && empty($_POST['age'])){

echo "All the entries were blank, please enter name(s) and age(s) on the left and click submit. Thank you.";

}

However, this doesn't parse as "true" when I click submit with the fields empty.

Is it not possible to use "empty()" with arrays and/or multidimensional arrays?

No comments posted yet

Your Answer:

Login to answer
55 Like 28 Dislike
Previous forums Next forums
Other forums

listcube issue
Hi
I have a virtual cube ZREMOTE. I use Tcode "listcube" to retrieve contents. I use of the

SELECT * FROM users WHERE Users are not in Blocked
How do I select all users from users table where there users_id is not stored in the block table

How can i steam a video on my PHP site? (non YouTube)
Basically I have a PHP site and don't want to give page rank to YouTube. I just want to stream a bas

Validating time
Hi Guys

what do you think of the following approach to validate a 24hour time:

http://

Generating unique numbers using php
Hi,
I need help in generating unique number using php.I tired using rand() in php.But, by using r

Get content from table into a list, without repeating.
Alright this is kinda an odd thing, so I need some help.

I have a table "quote" wit

IIS on 2003 anon access disabled issue
I have an IIS server that belongs to a domain, and anonymous access is turned off for all my sites.

How to restrict the display of report variants
Hello All,

I want t know how to restrict the display of report variants.
I mean, whe

file_put_contents and createimagefromjpeg
All,
I do somethings and then I have the following code:
file_put_contents('./test/'.$filename

have trouble in a if condition
The if below is working ok, it check when indexes, name, zipcode and state are empty.
Code: &

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash