Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9186969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:39:33+00:00 2026-06-17T19:39:33+00:00

I have a very large orderform, where customers can order different food. Here is

  • 0

I have a very large orderform, where customers can order different food.

Here is an example of my html (not completely sure if this is the correct way):

<legend>Dinner</legend>
<label for="beef">Beef</label>
<input type="text" id="beef" name="order[]dinner[][beef]" placeholder="How many beef plates do you want?">

<label for="chicken">Chicken</label>
<input type="text" id="chicken" name="order[]dinner[][chicken]" placeholder="How many chicken plates do you want?">


<legend>Desserts</legend>
<label for="cake">Cake</label>
<input type="text" id="cake" name="order[]desserts[][cake]" placeholder="How many cake slices do you want?">

<label for="pudding">Pudding</label>
<input type="text" id="pudding" name="order[]pudding[][cake]" placeholder="How many puddings do you want?">

How could I make a forloop to collect all the orders (where the value is over 0)

I have tried this code:

$order_array = $_POST['order'];

foreach ($order_array AS $key => $value){
    $order .= "<p><strong>$key:</strong> $value</p>\n";
}

But the output is this:

0: 30
1: 2

I would like it to be:

Beef: 30
Chicken: 1

Also, if possible could display the “category” like:

Dinner:
Beef: 30
Chicken: 1

Dessert:
Cake: 29
Pudding: 2

Edit:

Here is my post array:

array (
  'order' => 
    'Dinner' => 
    array (
      'beef' => '',
      'chicken' => '40',
    ),
    'Dessert' => 
    array (
      'Cake' => '',
      'Pudding' => '',
    ),
  ),
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T19:39:34+00:00Added an answer on June 17, 2026 at 7:39 pm

    First, change your inputs so that their names are in the following format:

    <input name="order[category][food]" />

    Then, once the data has been posted you can do something like the following to get the desired output:

    if (!empty($_POST['order'])) {
    
      foreach ($_POST['order'] as $type => $items) {
        echo '<strong>' . ucfirst($type) . '</strong><br />';
    
        foreach ($items as $name => $qty) {
          echo ucfirst($type) . ': ' . $qty . '<br />';
        }
        echo '<br />';
      }
    }
    

    Which would output something like the following:-

    Dinner
    Beef: 12
    Chicken: 2

    Dessert
    Cake: 4
    Pudding: 1


    Edit: If you need to prevent displaying categories ($type) from showing if there are no $items in them, you can do the following:

    if (count(array_filter($items))) {
      echo '<strong>' . ucfirst($type) . '</strong><br />';
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the main problem. I have very large database (25,000 or so) of
I have very large HTML that, if being parsed into DOM tree, would take
Here is a hypotetical scenario. I have very large number of user names (say
I have a very large file as: filename.bz2 , how can I view the
I have a very large Excel sheet converted from a 6000 page PDF file,
I have a very large UIView approx 3000x3000 in size. In this large view
I have a very large table of over 9 million rows and in my
I have a very large ASP.NET application in C#. The issue is simple yet
I have a very large data file with around 60000 rows. I need to
I have a very large possible data set that I am trying to visualize

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.