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 6867567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:19:33+00:00 2026-05-27T03:19:33+00:00

Possible Duplicate: Invalid argument supplied for foreach() How can I not to loop the

  • 0

Possible Duplicate:
Invalid argument supplied for foreach()

How can I not to loop the key with empty value in an array?

For instance, I want to skip [submit] => or [submit] => add from being looped in foreach,

Array ( 
[cart] => Array ( [1386638969582999] => Array ( [quantity_stock] => 10 ) ) 
[submit] => 
) 

the loop,

foreach ($_POST as $index => $array_items) 
{
    foreach($array_items as $id => $item)
    {
        $cart->add_item($id);
    }


}

I get this error,

Warning: Invalid argument supplied for foreach() in C:… on line xx

  • 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-05-27T03:19:33+00:00Added an answer on May 27, 2026 at 3:19 am

    Use is_array() to test if the key refers to an array:

    foreach ($_POST as $index => $array_items) 
    {
        // $_POST['submit'] won't be processed since it isn't an array
        if (is_array($array_items))
        {
          foreach($array_items as $id => $item)
          {
              $cart->add_item($id);
          }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Invalid argument supplied for foreach() I have the following code: <? foreach($format
Possible Duplicate: Detecting an “invalid date” Date instance in JavaScript I was using the
Possible Duplicate: Why not use tables for layout in HTML? Under what conditions should
Possible Duplicate: How can I take screenshots with Perl? How can I take a
Possible Duplicate: Why am I able to make a function call using an invalid
Possible Duplicate: How to pass an array via $_GET in php? So I have
Possible Duplicate: Error when echo $_GET[“jsoncallback”] <select name=test> <option value=1>1</option> <option value=2>2</option> <option value=3>3</option>
Possible Duplicate: The executable was signed with invalid entitlements I have made a app
Possible Duplicate: Perplexing Ruby/MySQL Error: "invalid packet: sequence number mismatch" My rails app just
Possible Duplicate: Lock the Android device programmatically I want to lock the screen through

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.