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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:54:54+00:00 2026-06-02T07:54:54+00:00

Here’s the code, it’s very simple: <?php $tab = array ( (object)array( ‘id’ =>

  • 0

Here’s the code, it’s very simple:

<?php
$tab = array (
    (object)array( 'id' => 1,),
    (object)array( 'id' => 4,),
    (object)array( 'id' => 12,),
    (object)array( 'id' => 22,),
    (object)array( 'id' => 25,),
);

$tab_json = array (
    (object)array( 'id' => 1,),
    (object)array( 'id' => 4,),
    (object)array( 'id' => 12,),
    (object)array( 'id' => 22,),
    (object)array( 'id' => 25,),
    (object)array( 'id' => 2,),
);
$difference = array_udiff($tab_json, $tab, function($a, $b) {
    echo $a->id." <-> ".$b->id."\n";
    return (count(array_diff_assoc(get_object_vars($a), get_object_vars($b))))>0;
});
?>

Here’s the output:

12 <-> 4
12 <-> 1
12 <-> 22
12 <-> 25
2 <-> 12
4 <-> 25
4 <-> 1
22 <-> 4
25 <-> 1
12 <-> 4
12 <-> 1
12 <-> 22
25 <-> 12
4 <-> 22
1 <-> 4
1 <-> 22
1 <-> 4
1 <-> 1
1 <-> 25
25 <-> 4
25 <-> 1
25 <-> 12
25 <-> 25
25 <-> 4
4 <-> 1
4 <-> 12
4 <-> 25
4 <-> 22
22 <-> 1
22 <-> 12
22 <-> 25
22 <-> 12
12 <-> 1
12 <-> 12
12 <-> 2
2 <-> 12
2 <-> 25

I don’t understand how it’s computed: look at 12: it’s compared more than 10 times (whereas, from what I understand, it should be compared no more than the number of elements of the second array), and moreover it’s compared three times with 1!

Tested on:

PHP 5.3.9
PHP 5.3.2-1ubuntu4.14
  • 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-02T07:54:55+00:00Added an answer on June 2, 2026 at 7:54 am

    The way array_udiff() actually produces its result is of course an implementation detail and subject to change. So while what I say might be true right now, you must not rely on it.

    For instance, if you need to use an old version of PHP, you might well implement a compatibility version of the function which simply compares each element of the first array against each element of the second array, discarding any that match.

    On the other hand, if you want the most performance, you would quicksort the elements of the second array, and then perform a binary search of the elements of the first array.

    PHP 5.3 seems to combine a quicksort with a linear search. It does however abort the search once it’s found a larger element.

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

Sidebar

Related Questions

here is my php code $titikPetaInti = array(); while($row = mysql_fetch_assoc($hasil2)) { $titikPetaInti[] =
Here is some simple code: DIR* pd = opendir(xxxx); struct dirent *cur; while (cur
Here a simple question : What do you think of code which use try
Here is my code: echo '<table class=class1><tbody>'; while ($row1=mysql_fetch_array($result1)){ echo '<tr><td>'.$row1['firstname'].'</td><td>'.$row1['lastname'].'</td></tr>'; } echo '</tbody></table>';
Here is the code: Function getData(ByVal id As String) Dim reader As SqlClient.SqlDataReader Dim
here is code: <script type=text/javascript> function doit(){ $('table td').each(function () { if ($(this).text().trim() !=
Here's a very simple repro: Start up VS2010 or VS2008, new a WPF project
Here's a piece of code I copied from http://www.schillmania.com/content/projects/javascript-animation-1/demo/ Very simple JS animation: function
Here's my proposed (very simplified to illustrate the problem space) design for a C#
Here's the code in AlertTableView: - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ NSInteger index = 12345; NSLog(@AlertTableView:

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.