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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:46:38+00:00 2026-05-30T17:46:38+00:00

I have a multidimensional array which looks like this: Array ( [0] => Array

  • 0

I have a multidimensional array which looks like this:

Array
(
    [0] => Array
        (
            [0] => Array
                (
                    [description] => UPS Ground
                    [delivery-time] => 1-5 business days
                    [shipping-amount] => 1299
                )

            [1] => Array
                (
                    [description] => UPS 3 Day Select
                    [delivery-time] => 3 business days
                    [shipping-amount] => 2459
                )

            [2] => Array
                (
                    [description] => UPS 2nd Day Air
                    [delivery-time] => 2 business days
                    [shipping-amount] => 3239
                )
        )

    [1] => Array
        (
            [0] => Array
                (
                    [description] => UPS Ground
                    [delivery-time] => 1-5 business days
                    [shipping-amount] => 864
                )

            [1] => Array
                (
                    [description] => UPS 3 Day Select
                    [delivery-time] => 3 business days
                    [shipping-amount] => 1109
                )

            [2] => Array
                (
                    [description] => UPS 2nd Day Air
                    [delivery-time] => 2 business days
                    [shipping-amount] => 1633
                )
             [3] => Array
                (
                    [description] => UPS Overnight
                    [delivery-time] => 1 business day
                    [shipping-amount] => 3528
                )

        )

)

I’m trying to achieve 3 things:

  1. Add the values of the shipping-amount where the description is the same across dimensions
  2. Drop the array if it contains a description which doesn’t exist in every other dimension
  3. Drop a dimension once the shipping-amounts are combined

There may be several first-level arrays (not just 2 as shown here), but this is as deep as the dimensions will go. I’m looking for the following result:

Array
(
    [0] => Array
        (
            [description] => UPS Ground
            [delivery-time] => 1-5 business days
            [shipping-amount] => 2163
        )
    [1] => Array
        (
            [description] => UPS 3 Day Select
            [delivery-time] => 3 business days
            [shipping-amount] => 3568
        )
    [2] => Array
        (
            [description] => UPS 2nd Day Air
            [delivery-time] => 2 business days
            [shipping-amount] => 4872
        )
) 

Thanks in advance!

  • 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-30T17:46:40+00:00Added an answer on May 30, 2026 at 5:46 pm

    I think this would work:

    $final=array(); // the final array
    $count=array(); // keeps track of instances of each description
    $loops=count($array);
    for($a=0;$a<$loops;$a++){
        foreach($array[$a] as $s){ //loop through child arrays
            if($count[$s['description']]>0){ //check if description exists in $count
                foreach($final as $k=>$v){ //add sums to the final if it does exist
                    if($final[$k]['description']==$s['description']){$final[$k]['shipping-amount']+=$s['shipping-amount'];}
                }
            }else{ //if it doesn't exist in the count array, add it to the final array
                $final[]=$s;
            }
            $count[$s['description']]++;//update the count array
        }
    }
    //Unset singletons, using the count array
    foreach($count as $k=>$v){
        if($v==1){
            foreach($final as $key=>$val){
                if($final[$key]['description']==$k){unset($final[$key]);}
            }
        }
    }
    print_r($final);
    

    I have been stuck on an issue for the past 2 days and feel you, so I hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a multidimensional-array which looks like this: $array = ( [0] => array
I have a php multidimensional array which looks like this: $fields = array( array('input',
I have a multidimensional array which, when echoed in PHP, looks like this: {
I have an multidimensional array that looks like this: Array ( [0] => Array
I have a multidimensional array that looks like this: Array ( [0] => Array
I have a multidimensional array. The contents look like this in the debugger. The
i have an multi-dimensional array which looks like $a[] = array('id' => '1', 'city'
I have a multidimensional array which I would like to sort by two factors:
how do I make a pointer to a multidimensional array, which have a unknown
I have CSV data loaded into a multidimensional array. In this way each row

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.