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

  • Home
  • SEARCH
  • 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 9101353
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T01:06:30+00:00 2026-06-17T01:06:30+00:00

I have a very simple form for products. Each product has a checkbox and

  • 0

I have a very simple form for products. Each product has a checkbox and quantity field that repeat creating an array of data like this:

<form action="process.php" method="post">
<input type="checkbox" name="product[]" value="product 1" />
<input type="text" name="quantity[]" />

<input type="checkbox" name="product[]" value="product 2" />
<input type="text" name="quantity[]" />

<input type="submit" />
</form>

Then I handle this form the following way in php:

//php script to retrieve data
$product    = isset($_POST['product'])  ? implode(', ', $_POST['product'])  : 'Not selected'; 
$quantity   = isset($_POST['quantity']) ? implode(', ', $_POST['quantity']) : 'Not mentioned'; 

$messageToSend = <<<END

Products:  $product - $quantity

END;

And the output result is for example: Products: product 1, product 2 – 10, 2

But what I am trying to achieve is the following output:
Products: product 1 – x 10, product 2 – x 2

Basically what I am trying to figure out is how to split and group data for each product in php script after I retrieved data.

Your help is very much appreciated.

  • 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-17T01:06:32+00:00Added an answer on June 17, 2026 at 1:06 am
    1. That doesn’t look completely php.
    2. You just have to iterate through both lists together:

      foreach ($quantity as $key => $quant) {
          echo $product[$key].' - x'.$quant;
      }
      

    This is the general idea, but as mentioned in the comments, doing this alone will is not the real solution.

    Some things to keep in mind:

    1. Checkboxes will not pass a value if they are not checked, so the $product array you get will not be the same size as, nor line up on key values with the $quantity array as you would like. (Try naming your checkboxes differently, I.e. product[1]). – thanks tmuguet
    2. If none of the checkboxes are checked, you will not get an array, so passing it to foreach will generate the error you mentioned.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very simple XAML form, that has one namespace definition. For some
I have a VERY simple windows form that the user uses to manage Stores.
I have a very simple model that includes the auto-filled field much like 'created'.
I have a very simple form with three fields that I need to submit
I have a very simple voting form. It contains a single text field for
I have a very simple GET form with one text field: <form action=blah method=get
I have a very simple form with a name field and two submit buttons:
I have a very simple PHP form, which shows a checkbox, and will store
I have very simple form that gets values in JSON format from searchAlbum.php .
I have a very simple Project form with a name field and a select

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.