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

  • Home
  • SEARCH
  • 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
  • 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-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

Ask A Question

Stats

  • Questions 491k
  • Answers 491k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Right click the application and choose "Run as different user".… May 16, 2026 at 10:11 am
  • Editorial Team
    Editorial Team added an answer You need this: SELECT * FROM Notification WHERE __key__ =… May 16, 2026 at 10:11 am
  • Editorial Team
    Editorial Team added an answer Windows has two kinds of pipes: anonymous pipes and named… May 16, 2026 at 10:11 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have array data as shown below, I want to store 'sale' value into
I have CSV file which has timestamp in the first column as shown below
I have a numpy array of pixel data that I want to draw at
I am trying to pass data around the numpy and boost::ublas layers. I have
i have 2 tables 1st table called services has id_service, name, date. description 2nd
Using Core Data. Let's say we have models for Team and Player. Assume: -Each
i need to push data in javascript array into database using PHP first i
I have a array with ID values like this [2,34,7,46,16,19 ...] etc each ID
I have an array, $scans. I want to query MySQL with all the values
I have an array which looks like this $dataArray = array ( 0 =>

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.