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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T16:51:49+00:00 2026-06-18T16:51:49+00:00

I have got an array that looks like: $costs = Array ( [0] =>

  • 0

I have got an array that looks like:

$costs = 
  Array
   (
    [0] => Array
       (
        [amount_set] => 27.99
        [amount_cost] => 17
        [amount_markup] => 3.6

    )

  )

  Array
      (
       [0] => Array
         (
        [amount_set] => 6.99
        [amount_cost] => 3.12
        [amount_markup] => 1          
       )

       [1] => Array
        (           
          [amount_set] => 16.99
          [amount_cost] => 10
          [amount_markup] => 2.54         
        )
)

What I’m looking to do is loop through the $cost array and for each one calculate a total value of amount_set.

If I use:

foreach($costs as $cost) {
   $amount +=$cost['amount_set'];
}

Then I will get the total of all combined amount_set values, but I just want to get the total of each individual one. For example my first total will be 27.99 and the second one should be 23.98. How would I go about doing this?

  • 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-18T16:51:50+00:00Added an answer on June 18, 2026 at 4:51 pm

    If I understand you correctly, $costs is an array of cost sets, which are arrays of costs, and you want the totals for each set. That would mean you need something like:

    foreach($costs as $cost_set) {
        $amount = 0;
        foreach ($cost_set as $cost) {
            $amount += $cost['amount_set'];
        }
        $amounts[] = $amount;
    }
    

    That will give yo an array of subtotals based on the groups of costs.

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

Sidebar

Related Questions

I have an array of hashes that looks like this: user_array = [<#Hashie::Mash id=1
I have a simple PHP Array called $categories that looks like this: Array (
I have a jagged array that looks like this: string[][] list = new string[d.Rows.Count
Alright, I've got an array that looks like. [0] => Array ( first_name =>
I have a 1D array that got i*50 elements..i is a random number and
I have a snippet of code that looks like so: if(array_key_exists('uid',$_SESSION)){ $userdata->readUser($_SESSION['uid']); $ACL =
I've got a group of data that looks like this: 001 001 One 001
I have a piece of C code that looks like this: const char (*foo)[2]
I've got a knockout View Model that looks like this: var TagViewModel = function
I have a table that looks something like this: <table> <tr id=1> <td>bla</td> </tr>

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.