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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:50:16+00:00 2026-06-15T19:50:16+00:00

I must be going crazy, I have a piece of code which iterates through

  • 0

I must be going crazy, I have a piece of code which iterates through a CSV file and goes through the records in our database. If the records in our csv file do no match the records in the database, then it will update the database accordingly.

To debug I printed the output of the two arrays. $dbEntry is the data already in the database. $entry is the data coming from the csv.

ksort($dbEntry);
ksort($entry);
var_dump($dbEntry);
echo "<br/>";
var_dump($entry);
echo "<br/>";
var_dump(array_diff($entry, $dbEntry));
echo "<br/>";
if ($overwrite == "on" && array_diff($entry,$dbEntry)) {
    //do sql update
{

The output is as follows:

array(11) { ["brand"]=> string(6) "xxx" ["id"]=> int(19220) ["lmf_comm"]=> int(0) ["lmf_pass"]=> int(0) ["period"]=> string(3) "Mar" ["pma"]=> string(6) "CEDUNA" ["sf_comm"]=> int(0) ["sf_pass"]=> int(34) ["tf_comm"]=> int(0) ["tf_pass"]=> int(0) ["year"]=> string(4) "2012" } 
array(11) { ["brand"]=> string(6) "xxx" ["id"]=> int(19220) ["lmf_comm"]=> string(1) "0" ["lmf_pass"]=> string(1) "0" ["period"]=> string(3) "Mar" ["pma"]=> string(6) "CEDUNA" ["sf_comm"]=> string(1) "0" ["sf_pass"]=> string(1) "0" ["tf_comm"]=> string(1) "0" ["tf_pass"]=> string(1) "0" ["year"]=> string(4) "2012" } 
array(0) { } 

Now i know they are different type casts but that shouldn’t matter (it hasn’t in the past). the index “sf_pass” is different – it is 34 in $dbEntry and 0 in $entry?

I don’t understand why it is given me nothing on the array_diff and therefore not entering the if statement beneath where I have mysql update query.

EDIT:

And it really doesn’t make sense because later in the CSV i get the following output from a different row. I don’t understand why the following will give me the output i’m looking for, whilst another row with pretty much identical values and typecasts not give me the output i’m looking for

array(11) { ["brand"]=> string(4) "yyy" ["id"]=> int(12) ["lmf_comm"]=> int(0) ["lmf_pass"]=> int(8) ["period"]=> string(3) "Jan" ["pma"]=> string(8) "FIVEDOCK" ["sf_comm"]=> int(5) ["sf_pass"]=> int(4) ["tf_comm"]=> int(14) ["tf_pass"]=> int(28) ["year"]=> string(4) "2012" } 
array(11) { ["brand"]=> string(4) "yyy" ["id"]=> int(12) ["lmf_comm"]=> string(2) "32" ["lmf_pass"]=> string(1) "8" ["period"]=> string(3) "Jan" ["pma"]=> string(8) "FIVEDOCK" ["sf_comm"]=> string(1) "5" ["sf_pass"]=> string(1) "4" ["tf_comm"]=> string(2) "14" ["tf_pass"]=> string(2) "28" ["year"]=> string(4) "2012" } 
array(1) { ["lmf_comm"]=> string(2) "32" } 
  • 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-15T19:50:17+00:00Added an answer on June 15, 2026 at 7:50 pm

    By default, the array_diff function only checks for values. And it does not considered how many times the value is repeated.

    use array_diff_assoc. It compares the array key by key.

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

Sidebar

Related Questions

I have a form which is going to contain 4 fieldsets. The user must
Must be a way looping through this code: private void loadSprites() { this.sprites[0] =
I think I must be going nuts here. I have a UINavigationController and in
I have been going crazy trying to get the selected option to align left
I must be going crazy but why is Groovy findIndexValues returning List<long> ? Can
This must be easier than I am making it, but I am going crazy
I'm going through my app, trying to clean up some code that sends e-mails.
I am implementing LDAP with PHP which is going fairly easily I must say.
CollectionUtils::removeAll() Commons Collections 3.2.1 I must be going crazy, becuase it seems like this
I feel like I must be going crazy, but I just changed the name

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.