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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:57:52+00:00 2026-06-08T18:57:52+00:00

Does in_array() do object comparison where it checks that all attributes are the same?

  • 0

Does in_array() do object comparison where it checks that all attributes are the same?
What if $obj1 === $obj2, will it just do pointer comparison instead?

I’m using an ORM, so I’d rather loop over the objects testing if $obj1->getId() is already in the array if it does object comparison. If not, in_array is much more concise.

  • 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-08T18:57:53+00:00Added an answer on June 8, 2026 at 6:57 pm

    in_array() does loose comparisons ($a == $b) unless you pass TRUE to the third argument, in which case it does strict comparisons ($a === $b).

    Semantically, in_array($obj, $arr) is identical to this:

    foreach ($arr as &$member) {
      if ($member == $obj) {
        return TRUE;
      }
    }
    return FALSE;
    

    …and in_array($obj, $arr, TRUE) is identical to this:

    foreach ($arr as &$member) {
      if ($member === $obj) {
        return TRUE;
      }
    }
    return FALSE;
    

    …and to quote the manual on what this actually checks:

    When using the comparison operator (==), object variables are compared in a simple manner, namely: Two object instances are equal if they have the same attributes and values, and are instances of the same class.

    On the other hand, when using the identity operator (===), object variables are identical if and only if they refer to the same instance of the same class.

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

Sidebar

Related Questions

I saw in Crockford's Book Javascript: The Good Parts that he does typeof comparison
I want to create a custom dictionary that does not copy its keys (just
Native Array in Emberjs does not support deep copy? I saw it just returning
How can i array a string, in the format that $_POST does... kind of,
Does anyone know how to shuffle two arrays randomly in exactly the same way
I've got a function that does (in short): my $file = IO::File->new(| some_command >>
I noticed the function Object.factory(char[] className) in D. But it does not work like
When an array of objects is not referenced anymore, does the objects in that
Can I check whether or not a given pointer points to an object within
In this sample(it's from the Oracle Site ) : // Notify all listeners that

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.