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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:35:09+00:00 2026-05-15T23:35:09+00:00

I have my array data as shown below: $array = [ [‘name’ => ‘Bank

  • 0

I have my array data as shown below:

$array = [
    ['name' => 'Bank BRI', 'amount' => 0], 
    ['name' => 'Bank BRI', 'amount' => 0], 
    ['name' => 'Bank BCA', 'amount' => 1412341234],
    ['name' => 'Bank CIMB Niaga', 'amount' => 532532552], 
    ['name' => 'Bank BRI', 'amount' => 34534534], 
    ['name' => 'Bank CIMB Niaga', 'amount' => 453425243], 
    ['name' => 'Bank BRI', 'amount' => 0], 
    ['name' => 'Bank BNI', 'amount' => 124124], 
    ['name' => 'Bank CIMB Niaga', 'amount' => 352345623], 
    ['name' => 'Bank BCA', 'amount' => 23432423], 
    ['name' => 'Bank Mandiri', 'amount' => 0], 
    ['name' => 'Bank BCA', 'amount' => 0], 
    ['name' => 'Bank BCA', 'amount' => 0], 
    ['name' => 'Bank Permata', 'amount' => 352352353],
];

How to sum ‘amount’ based on same ‘bank name’.

My result should show grouped names and their summed amount:

array (
  'Bank BRI' => 34534534,
  'Bank BCA' => 1435773657,
  'Bank CIMB Niaga' => 1338303418,
  'Bank BNI' => 124124,
  'Bank Mandiri' => 0,
  'Bank Permata' => 352352353,
)
  • 1 1 Answer
  • 1 View
  • 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-15T23:35:10+00:00Added an answer on May 15, 2026 at 11:35 pm
    <?php
    
    // array of bank structure
    $banks = array();
    $banks[] = array('name'=>'Bank BRI','amount'=>rand());
    $banks[] = array('name'=>'Bank BRI','amount'=>rand());
    $banks[] = array('name'=>'Bank BCA','amount'=>rand());
    $banks[] = array('name'=>'Bank CIMB','amount'=>rand());
    $banks[] = array('name'=>'Bank BRI','amount'=>rand());
    $banks[] = array('name'=>'Bank CIMB','amount'=>rand());
    $banks[] = array('name'=>'Bank BRI','amount'=>rand());
    $banks[] = array('name'=>'Bank BNI','amount'=>rand());
    $banks[] = array('name'=>'Bank CIMB','amount'=>rand());
    $banks[] = array('name'=>'Bank BCA','amount'=>rand());
    $banks[] = array('name'=>'Bank Mandiri','amount'=>rand());
    $banks[] = array('name'=>'Bank BCA','amount'=>rand());
    $banks[] = array('name'=>'Bank BCA','amount'=>rand());
    $banks[] = array('name'=>'Bank Permata','amount'=>rand());
    
    // begin the iteration for grouping bank name and calculate the amount
    $amount = array();
    foreach($banks as $bank) {
        $index = bank_exists($bank['name'], $amount);
        if ($index < 0) {
            $amount[] = $bank;
        }
        else {
            $amount[$index]['amount'] +=  $bank['amount'];
        }
    }
    print_r($amount); //display 
    
    // for search if a bank has been added into $amount, returns the key (index)
    function bank_exists($bankname, $array) {
        $result = -1;
        for($i=0; $i<sizeof($array); $i++) {
            if ($array[$i]['name'] == $bankname) {
                $result = $i;
                break;
            }
        }
        return $result;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function which sorts data in a multidimensional array, as shown below:
I have array data as shown below, I want to store 'sale' value into
I have an array as shown below which represents the ids of objects in
I have a JSON array as shown below : [{id:1,text: Hi this is text
I have aggregated data using pandas data frame. Below is some actual data shown
I have some array data returned from an ajax call consisting of an image
I have this array Array ( [data] => Array ( [0] => Array (
Let say I have an array like: Array ( [0] => Array ( [Data]
I am trying to sort an array. I have an array of data, where
I have a large array called data. At the 10th array position i have

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.