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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:18:16+00:00 2026-06-09T23:18:16+00:00

This is such a simple problem but the PHP doc does not explain why

  • 0

This is such a simple problem but the PHP doc does not explain why it is happening.

I have this code:

var_dump($newattributes); var_dump($oldattributes);
var_dump(array_diff($newattributes, $oldattributes));

For briefity I am going to omit large parts of the structure I am actually using (since each is 117 elements long) and cut to the case.

I have one array called $newattributes which looks like:

array(117){
    // Lots of other attributes here
    ["deleted"] => int(1)
}

And another called $oldattributes which looks like:

array(117){
    // Lots of other attributes here
    ["deleted"] => string(1) "0"
}

Which looks different right? According to array_diff: no. The output I get from array_diff is:

array(0) { } 

I have read the documentation page however it says:

Two elements are considered equal if and only if (string) $elem1 ===
(string) $elem2. In words: when the string representation is the same.

And I am not sure how “1” can object equal “0”.

So am I seeing some caveat with array_diff I didn’t take into consideration?

  • 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-09T23:18:17+00:00Added an answer on June 9, 2026 at 11:18 pm

    The problem might reside in the fact that you are using associative arrays : you should try and use the following for associative arrays : array_diff_assoc():

    <?php 
        $newattributes = array(
           "deleted" => 1 
        );
    
        $oldattributes = array(
           "deleted" => "0" 
        );
    
        $result = array_diff_assoc($newattributes, $oldattributes);
    
        var_dump($result);
    ?>
    

    result :

       array(1) {
           ["deleted"]=>
           int(1)
       }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this must be such a simple problem but can someone tell me why this
This is such a simple problem, but I can't find an answer anywhere... I
sorry this is such a simple question but I can't figure it out. How
This seems like such a simple issue but I cannot find an elegant solution.
This seems like such a simple question. I have several Edit boxes on my
I have a relatively simple HTML / JavaScript form. Such as this: <form method='POST'
I'm trying to figure this simple thing but I'm actually embarrassed to ask such
I have a Linode (Ubuntu 9.10, but upgrading not a problem) where I run
This is driving me absolutely bonkers, and it seems like such a simple thing
I have this such query : SELECT au_lname,der.col FROM authors INNER JOIN (SELECT t.au_id,

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.