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

trim function issues
Hi guys, total noob here...

So I've been tinkering around with a html and am using php to em

Parse Error
Hi Guys,

I have a function in my class which returns a string link variable. The problem is i

Upload Code Help
Hi everyone I need some help with a bit of code ive been working with for a while. I am completely s

Help With Showing Users On the Index Page
Ive got this code which works just how i want it to.

Code: <?
$timenow=time();

Port scanner problem
Hai
recently i developed one app through which u can check the opened and closed ports under an

Multiple forms on the same page (safari)
Hello everyone,

I have 3 forms on the same page, that opens in a new window and submits to a

Best way to cross matching large datasets
Hi,

Im running a script where am I cross matching about 200 000 data sets with each other. Ea

Notice Undefined index: reset/ Attempting to redirect, works, but get a notice
Full Header.php is:
Code: [Select]<?php
$reset= false;
$reset= strip_tags($_GET[&quo

Merger of 6 sister companies under one flagship company after go live
Dear Experts,
I need one help regarding Merger of sister companies of same group. currently we

Form a inline view based on the results of the previous query?
Hi Experts,
Can we form a inline view on the results of a previous query (another inline view)?

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