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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:06:50+00:00 2026-06-13T09:06:50+00:00

I have an array coming from a SQL query that follows the following format:

  • 0

I have an array coming from a SQL query that follows the following format:

[ 
  ["2012-10-01", 1, 3890], 
  ["2012-10-01", 0, 8900], 
  ["2012-09-21", 0, 8900], 
  ["2012-09-21", 1, 8900], 
  ...
]

At the end I want to have the counts for 0s and 1s. So for example, for the date 2012-10-01, I would have that the value 1 have a count 3890 and the value 0 have a count 8900. I want to know how I can iterate this array in order to build a final array like this:

$final_array["value0"]["2012-10-01"] = 3890
$final_array["value1"]["2012-10-01"] = 8900
$final_array["total"]["2012-10-01"] = 12790

Taking into account that it can happen that a date doesn’t have a count for value 0 or 1, and the order of value 0 and 1 is not always the same.

So the first example could be like this:

[ 
   ["2012-10-01", 1, 3890], 
   ["2012-09-21", 1, 8900], 
   ["2012-09-21", 0, 8900], 
   ...
]

As you can see the first date is lacking of value 0 and the final array would still have to have it like this:

   $final_array["value0"]["2012-10-01"] = 3890
   $final_array["value1"]["2012-10-01"] = 0
  • 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-06-13T09:06:51+00:00Added an answer on June 13, 2026 at 9:06 am

    Here is the code. You really should try to work it out yourself first, because this is basic array mapping.

    foreach($initialarray as $data){
        $finalarray["value".$data[1]][$data[0]]=$data[2]; 
    }
    

    EDIT: Here is code that fulfils your updated requirements:

    $initialarray = array(array("2012-10-01", 1, 3890), array("2012-09-21", 1, 8900), array("2012-09-21", 0, 8900));
    $finalarray["value0"]=array();
    $finalarray["value1"]=array();
    foreach($initialarray as $data){
        $finalarray["value".$data[1]][$data[0]]=$data[2]; 
        $finalarray["value".round(cos($data[1]*pi()/2))][$data[0]]=$finalarray["value".round(cos($data[1]*pi()/2))][$data[0]]?$finalarray["value".round(cos($data[1]*pi()/2))][$data[0]]:0;
    }
    echo "<pre>";
    var_dump($finalarray);
    echo "<pre>";
    

    DEMO

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

Sidebar

Related Questions

I have an array coming from my database I want to format and display
I have an array $eps coming from MYSQL table and I want to output
I have the following array coming from a form submission: Array ( [id0] =>
I have discovered that results coming from my SQL Server are having the field
I have four arrays that are coming in from the client. Let's say that
I have a problem here in JSTL, I have an array object coming from
I have 2 arrays - one array is coming from the database, another from
HI All, I'm concerned, I have an array coming in from a server. The
I have this $_POST array coming from a paypal transaction Array ( [address_city] =>
I have several variables coming from an array in $POST_['array'] i wish to make

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.