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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:07:02+00:00 2026-05-23T11:07:02+00:00

I have a multi dimensional array with some data. Array ID Date Quantity 66998

  • 0

I have a multi dimensional array with some data.

    Array  ID      Date     Quantity
    66998  [0] [2011-05-11] [50]
           [1] [2011-05-15] [50]
           [2] [2011-05-15] [50]
    81158  [0] [2011-05-11] [25]
           [1] [2011-05-12] [60]
           [2] [2011-05-16] [60]
           [3] [2011-05-18] [60]

I would like to add up all the Quantities from orders within same week. I can calculate the week number with:

            $WeekNumber = date("W", $UnixTimestamp);

So the final array should look like this:

               Week Quantity
    66998  [0] [19] [150]
    81158  [0] [19] [85]
           [1] [20] [120]    

The array is generated from MS SQL database.

  • 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-23T11:07:03+00:00Added an answer on May 23, 2026 at 11:07 am

    You could use array_reduce($array, 'function_name') to produce the result array one step at a time.

    function calc_weeks($result, $row)
    {
        . . .
        $WeekNumber = date("W", $UnixTimestamp);
        $result[$weekNumber] += $row['quantity'];
        return $result;
    }
    array_reduce($array, 'calc_weeks', array());
    

    Alternatively you could use SQL to calculate week numbers and sum your orders that way. In MySQL the function is called WEEK(). For MS SQL there’s a related question here.

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

Sidebar

Related Questions

I have a multi dimensional array, like this: array('name' => array('title'=>'Title','date'=>'Created')) I store it
If I have a multi dimensional array in PHP like so... [0] => Array
Possible Duplicate: php multi-dimensional array remove duplicate I have an array like this: $a
I have some code that creates a multi-dimensional array, but my result seems to
Is it possible to map key to Multi Dimensional Array List. Some thing like
I have a multidimensional array, and I would have multiple arrays within it. Some
I have a multi-dimensional array, which basically consists of one sub-array for each year.
I have a multi-dimensional array, no problem. How do I interrogator one of the
I have a multi dimensional array. The only actual values (other than other arrays)
I have an multi-dimensional array that I want to send to a PHP script

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.