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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:45:50+00:00 2026-06-01T10:45:50+00:00

I have the array shown below. I would like to have a resultant array

  • 0

I have the array shown below. I would like to have a resultant array where value in the key elements [tv], [tu], [cost], [km] are summed for all the row with same value of [tick_id]. In this example we should sum the value [tv], [tu], [cost], [km] of the array elements 0, 1, 2, … How can I do this?

Array (
    [0] => stdClass Object (
        [id] => 15
        [user_id] => 44
        [name] => inspector1
        [tv] => 0.00
        [tc] => 0.00
        [tu] => 0.00
        [cost] => 0.00
        [kms] => 0
        [date_s] => 2012-03-30
        [notes] =>
        [tick_id] => 11
        [tot_fee] => 5500
    )
    [1] => stdClass Object (
        [id] => 39
        [user_id] => 46
        [name] => Assistant
        [tv] => 10.00
        [tc] => 0.00
        [tu] => 4.50
        [cost] => 0.00
        [kms] => 120
        [date_s] => 2012-03-31
        [notes] =>
        [tick_id] => 15
        [tot_fee] => 0
     )
    [2] => stdClass Object (
        [id] => 35
        [user_id] => 46
        [name] =>
        [tv] => 0.00
        [tc] => 0.00
        [tu] => 0.00
        [cost] => 0.00
        [kms] => 0
        [date_s] => 2012-03-30
        [notes] =>
        [tick_id] => 13
        [tot_fee] => 3200
    )
    …
)
  • 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-01T10:45:52+00:00Added an answer on June 1, 2026 at 10:45 am

    It’s hard to tell with the way your code is displaying but this should be what you need:

    // Create the cost total array
    $cost = array();
    
    // Iterate over each object in the given array
    foreach ($array as $object)
    {
    
      // If the tick_id has not yet been assigned as a key then do so with a default cost of 0
      if (!isset($cost[$object->tick_id]))
      {
        $cost[$object->tick_id] = 0;
      }
    
      // Increment the total cost for the given tick_id
      $cost[$object->tick_id] += $object->tv + $object->km + $object->tu + $object->cost;
    
    }
    

    $cost will be an array where the key is the tick_id and the value is the total cost.

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

Sidebar

Related Questions

I have array of strings, String[] data and it's 10 elements has value P
An array is defined of assumed elements like I have array like String[] strArray
I have two MySQL tables named 'nodes' and 'joinTable' like shown below. I need
I have an array shown below [ 'http://api.tweetmeme.com/imagebutton.gif?url=http://mashable.com/2010/09/25/trailmeme/', 'http://cdn.mashable.com/wp-content/plugins/wp-digg-this/i/gbuzz-feed.png', 'http://mashable.com/wp-content/plugins/wp-digg-this/i/fb.jpg', 'http://mashable.com/wp-content/plugins/wp-digg-this/i/diggme.png', 'http://ec.mashable.com/wp-content/uploads/2009/01/bizspark2.gif', 'http://cdn.mashable.com/wp-content/uploads/2010/09/web.png', 'http://mashable.com/wp-content/uploads/2010/09/Screen-shot-2010-09-24-at-10.51.26-PM.png',
I have an array of strings(as shown in example). I just wish to find
I have array of select tag. <select id='uniqueID' name=status> <option value=1>Present</option> <option value=2>Absent</option> </select>
I have array like this: $path = array ( [0] => site\projects\terrace_and_balcony\mexico.jpg [1] =>
I have array result like this: Array ( [0] => stdClass Object ( [id_global_info]
So I have a sort of zigzag pattern, as shown below. , which is
I have several Div's that appear and would like each one to have a

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.