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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:48:34+00:00 2026-05-27T19:48:34+00:00

I have some data for my sites statistics in a SQL DB: date: visits:

  • 0

I have some data for my sites statistics in a SQL DB:

date:          visits:        pageviews:
12-12-12       34             21
12-12-13       31             22
12-12-14       33             2445
12-12-15       35             2422
12-12-16       36             232

//ect ect

I’m trying to create a Multidimensional array that contains all the dates info from the DB and where the date will be the key (selector,name of the array inside the multi array), so as the end result, I should be able to just do this:

print_r $my_multi_array[12-05-12];

And I should see the statistics for that date on the screen.

Now I know how to do all the loops and stuff, and I even have a good idea about how to do multidimensional arrays, it’s just that I think I’m doing something wrong:

//first things first, define the array:
$my_multi_array=array();

//then, in a loop, append to the array:
$my_multi_array[]=array("$date"=>array('visits'=>mysql_num_rows($visit_query),'pageviews'=>$pageview_query));

Now when I print_r that array, everything looks good:

Array ( [0] => Array ( [11-12-24] => Array ( [visits] => 1 [pageviews] => 0) ) [1] => Array ( [11-12-25] => Array ( [visits] => 1 [pageviews] => 0) ) [2] => Array ( [11-12-26] => Array ( [visits] => 1 [pageviews] => 0)))1

Notice the 1 at the end ^^. That seemed to be in the result (not a typo).

Now when I try printing a certain array out (using the date as the key):

print_r $my_multi_array['11-12-24'];

I get:

1

So then i try:

print_r $my_multi_array[2];

and that works fine.

For some reason, it wont let me select an array from $my_multi_array using the date as the key.

Any ideas on how to fix this?

thanks

  • 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-27T19:48:35+00:00Added an answer on May 27, 2026 at 7:48 pm

    You have to put the date as the array key, like so:

    $my_multi_array[$date]=array("$date"=>array('visits'=>mysql_num_rows($visit_query),'pageviews'=>$pageview_query));
    

    Notice the $my_multi_array[$date].

    By doing $my_multi_array[] = ... you are just creating a new numerical index on the array with the content on the right side. That’s why when you access the array with the numerical index, like $my_multi_array[2], it works.

    On the other hand, by doing $my_multi_array[$date]you are treating the array like an hash table, where you associate a key (in this case a string containing a date) with a value.

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

Sidebar

Related Questions

I have a php script which when fired, collects some data on different sites
I have some data with messed-up accented characters. For example in the data we
I have some data grouped in a table by a certain criteria, and for
I have some data of the form Key ID Link 1 MASTER 123 2
I have some data. I want to go through that data and change cells
I have some data that I want to store somewhere in my Rails app
I have some data stored as ArrayList . And when I want to backup
I have some data files to import into a database with some unique delimiters:
I have some data in an Excel Worksheet. I would like to select all
I have some data with one row of headers and one or more rows

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.