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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:20:18+00:00 2026-05-24T23:20:18+00:00

I have 2 arrays Array ( [010156] => Array ( [supp_number] => 010156 [totalamount]

  • 0

I have 2 arrays

Array
(
    [010156] => Array
    (
        [supp_number] => 010156
        [totalamount] =>     4.113,23
        [debtorcred] => H
        [amount1] =>     4.113,23-
        [amount2] =>

        [amount3] =>
        [amount4] =>
        [amount5] =>
        [amount6] =>
    )
)



Array
(
    [010156] => Array
    (
        [supp_number] => 010156
        [totalamount] =>     4.113,23
        [debtorcred] => H
        [amount1] =>     4.113,23-
        [amount2] =>

        [amount3] =>
        [amount4] =>
        [amount5] =>
        [amount6] =>
    )
)

Is it possible that I can combine these separate arrays into one and add the values together so that the outcome will be:

Array
(
    [010156] => Array
    (
        [supp_number] =&gt;  <<<TOTAL >>>
        [totalamount] =&gt;     <<<TOTAL >>>
        [debtorcred] =&gt; <<<TOTAL >>>
        [amount1] =&gt;      <<<TOTAL >>>
        [amount2] =&gt;  <<<TOTAL >>>

        [amount3] =&gt;  <<<TOTAL >>>
        [amount4] =&gt;  <<<TOTAL >>>
        [amount5] =&gt;  <<<TOTAL >>>
        [amount6] =&gt;  <<<TOTAL >>>
    )
)

This is the function I have at the moment but I cannot seem to make it work:

function array_merge_numeric_values()
{
  $arrays = func_get_args();
  $merged = array();
  foreach ($arrays as $array)
  {
    foreach ($array as $key => $value)
    {
      if ( ! isset($merged[$key]))
      {
        $merged[$key] = $value;
      }
      else
      {
        $merged[$key] += $value;
      }
    }
  }
  • 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-24T23:20:19+00:00Added an answer on May 24, 2026 at 11:20 pm

    This actual calculation can be done in 2 lines of code, no need for loops:

    http://codepad.viper-7.com/ieSkHQ

    $arr1 = array('amount1' => 1, 'amount2' => 6);
    $arr2 = array('amount1' => 2, 'amount2' => 7);
    $add = function($a, $b) { return $a + $b; };
    $summedArray = array_map($add, $arr1, $arr2);
    print_r($summedArray);
    

    Youl’ll just need to make the appropriate adjustment to account for you nested structure.

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

Sidebar

Related Questions

I have two arrays: Array ( [2005] => 0 [2006] => 0 [2007] =>
A PHP array can have arrays for its elements. And those arrays can have
Consider I have two arrays: $friends = Array('foo', 'bar', 'alpha'); $attendees = Array('foo', 'bar');
I have two arrays in PHP. The first array ($author_array) is comprised of user_ids
I have two arrays of animals (for example). $array = array( array( 'id' =>
I have three arrays, all the same size: xout % cell array xin %
I have a multidimensional array, and I would have multiple arrays within it. Some
Assume that we have multiple arrays of integers. You can consider each array as
How can I store arrays in single array? e.g. I have four different arrays,
I have an array that contains an array of arrays if that makes any

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.