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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:56:19+00:00 2026-06-14T09:56:19+00:00

Here is the array: [cart] => Array ( [ProductId] => Array ( [0] =>

  • 0

Here is the array:

 [cart] => Array
        (
            [ProductId] => Array
                (
                    [0] => P121100001
                    [1] => P121100002
                )

            [SellerId] => Array
                (
                    [0] => S12110001
                    [1] => S12110001
                )

            [SpecifyId] => Array
                (
                    [0] => 1
                    [1] => 2
                )

            [Quantity] => Array
                (
                    [0] => 1
                    [1] => 1
                )

            [Price] => Array
                (
                    [0] => 12
                    [1] => 29
                )

            [TotalPrice] => 41
        )

I have the ProductId and I want to remove all the other items matching P121100002’s key.

Is there an easy way to do this I can’t can seem to come up with one?

  • 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-14T09:56:20+00:00Added an answer on June 14, 2026 at 9:56 am

    You can loop through the full array and use unset() to, well, “unset” the specified index:

    $index = array_search($cart['ProductId'], 'P121100002');
    if ($index !== false) {
        foreach ($cart as $key => $arr) {
            unset($cart[$key][$index]);
        }
    }
    

    The slight caveat to this approach is that it may disrupt your index orders. For instance, say you have:

    [ProductId] => Array (
        [0] => P121100001
        [1] => P121100002
        [2] => P121100003
    )
    

    And you want to remove P121100002, which has a corresponding index of 1. Using unset($cart['ProductId'][1]) will cause your array’s to become:

    [ProductId] => Array (
        [0] => P121100001
        [2] => P121100003
    )
    

    This may be something to remain concerned with if you’re going to use a for loop to iterate through in the future. If it is, you can use array_values() to “reset” the indexes in the unset() loop from above:

    foreach ($cart as $key => $arr) {
        unset($cart[$key][$index]);
        $cart[$key] = array_values($cart[$key]);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So i have a class name repository which is just a simple array.Here is
Here is my problem: I have an array of model class(Let's say, 'addressModel' with
Here is an example of an array that is output: Array ( [CART] =>
I have a session array [cart] of which contains user id numbers. I am
I have a very simple cart which displays the item quantity in a text_field,
I'm making shopping cart, and I have s problem displaying the products. Here's a
if($err) $_SESSION['msg']['login-err'] = implode('<br />',$err); Three quick questions: Why use a two-dimensional array here?
$.getJSON(./data/revenue-item-data.php,{val:'val'},function(data){ $('#totalUnits').val(data[0].SUM(item_qty)); $('#totalAmounts').val(data[0].SUM(DISTINCT net_total)); }); Here is array I get for above code: [{SUM(item_qty):68,SUM(DISTINCT
Here is my array that is put together: Array ( [1] => Array (
Here's the array which I m trying to convert to a JSON Object: Array

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.