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' >
Did you know?Explore Trending and Topic pages for more stories like this.

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

How could I do this?
Ive got a simple lottery game, and am using an sql database to keep track of the numbers bought. But

mysql query with single quotes in a variable
$sitedetails = "INSERT INTO vars (address, sitename, description, ownername, theme) VALUES ('$u

Basic Forum Tutorial
Hi, I'm new to PHP. I want to build a basic forum for my site using PHP and MySQL. I've searched t

Help building / using array
First - this is a cross-posting, if this is wrong I apologise! What started out as a MySQL query que

Format timestamp from mysql
When I tried this:
Code: date("m/d/Y H:i A", $row['timestamp'])
I got 12/31/1969 18:

Passing PHP variables from one page to another
Hello-

I'm having trouble figuring out how to transport a variable from one php file to anoth

New Search Engine
Hey everyone,

I have a ZIP Code Radius search engine already functional. it displays all of t

shoping cart issues
i´ve wrote this and works when i add an item to, my cart, but when i want to add othrer item just

PHP FTP connect doesn't work with correct login
Hi!

i am working on this test code:
Quote<?php

$ftp_ser

disable all input buttons
Hello Friends,

suppose i do have a file ( file.php ) has a submit button

Code: [Sele

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