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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T14:10:02+00:00 2026-05-11T14:10:02+00:00

I have a dataset obtained from MySQL that goes like this: Array ( [0]

  • 0

I have a dataset obtained from MySQL that goes like this:

 Array (     [0] => Array         (             [views] => 14             [timestamp] => 06/04             [views_scaled] => 4.9295774647887             [unix_time] => 1239022177         )      [1] => Array         (             [views] => 1             [timestamp] => 19/04             [views_scaled] => 0.35211267605634             [unix_time] => 1240194544         )          ...         ...         ...  ) 1 

(it’s post-processed, ‘timestamp’ was really a timestamp before, but that doesn’t matter anyways)

The array is stored on $results, and in the middle of my code I do something like this:

 $results = array_merge($results, $new_days); $a = $results; foreach ($results as $row) {     $unix_time[] = $row['unix_time']; } $b = $results; 

The problem: $a and $b are both different. The first one shows the array as it’s supposed to, and the second one has the same count(), but it’s fourth element is a duplicate from the last one. As far as I know, I’m not passing anything by reference, so $results Isn’t meant to change (maybe the pointer, but not it’s content). I’m using PHP 5.2.4 on Mac OS X 10.5.2.

The obvious question: Is this somehow the intended behavior, a bug or I’m doing something wrong here? (not a boolean answer please 😉


EDIT: Thank you all for the interest, I don’t know exactly how much extra code should I post, I don’t do much before except for retrieving the data from the DB and a foreach to parse the timestamp and build a new array ($new_days) for the missing days. This is all working fine.

This code goes after the one I’ve posted early:

 array_multisort($unix_time, SORT_ASC, $results); $days = implode('|', array_pluck('timestamp', $results)); $views = implode('|',  array_pluck('views', $results)); $views_scaled = implode(',', array_pluck('views_scaled', $results)); 

(array_pluck() is a custom function to generate an array from a column in a typical DB-dumped dataset)


EDIT 2: Thanks again, here’s the full snippet and the output from the $results array $a and $b (also referenced in the code’s comments).

  • 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. 2026-05-11T14:10:03+00:00Added an answer on May 11, 2026 at 2:10 pm

    Inspecting your code snippet, really quickly (just about to leave the office for the day), it is probably to do with something passing by reference in your (first) loop. Try using normal by value and just storing everything into a fresh result array. (will remove any mysteries that could be going on). Could also try making the second $row in the second foreach a different name.. beats me – can’t tell you with really looking at this more.

    also this line and following block of code won’t execute

    if ($last_day != $day_before_this_one AND $last_day) 

    could have something to do with it, new days will never fill up and the merge could be doing something funky.

    Wouldn’t call this an answer but its a start to look at I guess

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Are you running on OS 3.0? I saw the same… May 12, 2026 at 1:19 am
  • Editorial Team
    Editorial Team added an answer It looks like you need to register Apache::Session::Memcached with Apache::Session::Wrapper,… May 12, 2026 at 1:19 am
  • Editorial Team
    Editorial Team added an answer Use DATENAME or DATEPART: SELECT DATENAME(dw,GETDATE()) -- Friday SELECT DATEPART(dw,GETDATE())… May 12, 2026 at 1:19 am

Related Questions

I have a dataset that I have modified into an xml document and then
I have a DataSet which I get a DataTable from that I am being
I have a dataset that has two tables in it. I want to do
I have a DataSet that contains a few columns. One of these columns is

Trending Tags

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

Top Members

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.