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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:47:11+00:00 2026-05-13T23:47:11+00:00

Array ( [0] => Array ( [datas] => Array ( [name] => lorem [id]

  • 0
Array
(
[0] => Array
    (
        [datas] => Array
            (
                [name] => lorem
                [id] => 1
                [type] => t1
                [due_type] => Q1
                [t1] => 1
                [t2] => 1
                [t3] => 1
            )

    )

[1] => Array
    (
        [datas] => Array
            (
                [name] => lorem
                [id] => 1
                [type] => t2
                [due_type] => Q1
                [t1] => 0
                [t2] => 1
                [t3] => 0
            )

    )

[2] => Array
    (
        [datas] => Array
            (
                [name] => name
                [id] => 2
                [type] => t1
                [due_type] => Q1
                [t1] => 1
                [t2] => 0
                [t3] => 1
            )

    )

[3] => Array
    (
        [datas] => Array
            (
                [name] => name
                [id] => 2
                [type] => t2
                [due_type] => Q1
                [t1] => 1
                [t2] => 0
                [t3] => 0
            )

    )

)

I want to add the values of each array according to its id, but I am having problem getting the values using these code: I want to compute the sum of all type according to each due_type and combining them into one array.

$totals = array();
$i = -1;
foreach($datas as $key => $row){
    $i += 1;
    $items[$i] = $row;

    if (isset($totals[$items[$i]['datas']['id']])){
        if($totals[$items[$i]['datas']['id']]['due_type'] == 'Q1'){

            if($totals[$items[$i]['datas']['id']]['type'] == 't1'){
                $t1+=$totals[$items[$i]['datas']['id']]['t1'];
            }elseif($totals[$items[$i]['datas']['id']]['type'] == 't2'){
                $t2+=$totals[$items[$i]['datas']['id']]['t2'];
            }elseif($totals[$items[$i]['datas']['id']]['type'] == 't3'){
                $t3+=$totals[$items[$i]['datas']['id']]['t3'];
            }
            $totals[$items[$i]['datas']['id']]['t1_total'] = $t1;
                    $totals[$items[$i]['datas']['id']]['t2_total'] = $t2;
        }
    }
    else {
        $totals[$items[$i]['datas']['id']] = $row['datas'];
        $totals[$items[$i]['datas']['id']]['t1_total'] = $items[$i]['datas']['t1'];
            $totals[$items[$i]['datas']['id']]['t2_total'] = $items[$i]['datas']['t2'];
    }
}
  • 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-13T23:47:11+00:00Added an answer on May 13, 2026 at 11:47 pm

    Not sure what output you want, but this:

    function condense($data, $condensed = array()) {
    
        foreach($data as $row) {
            $id = $row['datas']['id'];
            $due_type = $row['datas']['due_type'];
            $type = $row['datas']['type'];
            if(!array_key_exists($id, $condensed)) {
                $condensed[$id] = array();
            }
            if(!array_key_exists($due_type, $condensed[$id])) {
                $condensed[$id][$due_type] = array();
            }
            if(!array_key_exists($type, $condensed[$id][$due_type])) {
                $condensed[$id][$due_type][$type] = 0;
            }
            $condensed[$id][$due_type][$type] += $row['datas'][$type];
        }
    
        return $condensed;
    }
    
    $result = condense($data);
    

    gives you:

    Array
    (
        [1] => Array
           (
               [Q1] => Array
                   (
                      [t1] => 1
                      [t2] => 1
                   )
           )
        [2] => Array
           (
               [Q1] => Array
                   (
                      [t1] => 1
                      [t2] => 0
                   )
           )
    
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello everyone I am completely stuck with this problem. I want add the name
I've got a problem with those data, my json array data contains: {list_file:[{\id\:\511\,\name\:\Jellyfish.jpg\,\projectId\:\12539\,\projectName\:\project namessszd
I have an array called billItems in my jquery, and am having values in
postgres has an array data type, in this case a numeric array: CREATE TABLE
I have a problem related to an array data which fetched from an external
I have a json output array like this { data: [ { name: Ben
I have 3 json arrays, each with information listed in the same format: Array:
I have my array data as shown below: $array = [ ['name' => 'Bank
How do I access the returned JSON Data? e.g the name array? to work
I am getting one value by JSON array, but how can I store multiple

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.