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

Why does my php page download images over and over
Can anybody please explain to me why my php page keeps downloading the images and other items every

Hyperlink in PHP to MySQL record
Hello,

I am having trouble as i am new to php. I have connected to the database and I have di

Buggy registration system
Hey, I just started scripting in PHP, and I ran into a few problems.
Code: <?php
includ

adding up might be solved tell us cheers.
i think i finally solved this anybody.

last time i was getting the wrong results.

Code

batch file not building to webapps folder
Hello. I just started running Vista :P and can't seem to get my projects deployed. I found out how

Ignore html and bbcode?
I've created a function to limit the amount of text according to the amount of words.

However

Stopping page post back
I have few literal contriols in my page and a repeater too. But inspite of using update panel, postb

Extending Exception to contain method name
I was wondering, if there's a way to extend Exception in such a way, that it would contain name of a

Multi-image upload problems
Lets see if I can get some help on this one. Can anyone show me what I am doing wrong here. I'm just

i have no idea why this isn't working
Code: <?php
session_start();
include("connect.php");

error_reporting(E

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