# [PHP-CVS] cvs: php-src /ext/standard array.c basic_functions.c php_array.h

- Thread: https://externals.io/message/4564
- Original archive: https://news-web.php.net/php.internals/4564
- Started by Andrey Hristov on 2003-09-24T09:56:52+00:00
- Messages: 1
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #4564 — Andrey Hristov — 2003-09-24T09:56:52+00:00

URL: https://externals.io/message/4564#4564

Wez Furlong wrote:
 > Should these functions really go into the core?
 > Perhaps they are better off in an extension (pecl/array_utils ?)
 >
 > The names aren't really all that obvious to me either.
 >
 > --Wez.

Hi Wez,
well maybe `array_udiff_uassoc()` and `array_diff_uassoc()` are of little 
need but I added them for completeness to `array_udiff()` and 
 `array_udiff_assoc()`. It's easy not to export `array_udiff_uassoc()` and 
 `array_diff_uassoc()` and this won't hurt me. However I think that 
 `array_udiff()` and `array_udiff_assoc()` are useful. As I stated in my talk 
to Jani, in 4_3 it is impossible to use `array_diff()` or 
 `array_diff_assoc()` on arrays that contain objects. When I started to 
implement (and implemented) these functions few months ago I had no need 
of them, I did it for fun.  However, month or two ago I faced a case 
where I needed this functionality but unfortunately it wasn't available 
so I had to find a way to workaround it.
  Let me show you a small example :
<?php
class CPerson {
         private $priv_member;
         public  $public_member;
         function CPerson($val) {
                 $this->priv_member = $val;
                 $this->public_member = $val;
         }
         static function comp_func_cr($a, $b) {
                 if ($a->priv_member === $b->priv_member) return 0;
                 return ($a->priv_member > $b->priv_member)? 1:-1;
         }
}// class CPerson
$a = array(
     "0.1" => new cr(9),
     "0.5" => new cr(12),
     0 => new cr(23),
     1=>  new cr(4),
     2 => new cr(-15),
);
$b = array("0.2" => new cr(9),
     "0.5" => new cr(22),
     0 => new cr( 3),
     1=> new cr(4),
     2 => new cr(-15),
);
?>
In this case $a and $b contain objects. Even more they have private 
member variables. `array_diff()` is in no use here since it _cannot_ work 
with objects well : if I execute array_diff($a, $b) the returned array 
will contain the elements of $a . So, what to do to make a diff of the 
two arrays and not to code a function (in PHP) for that by myself? -> 
Implement core function for that. This functionality goes to 5.0.0 where 
the object model is better and if core functions can work well with 
object(s) it will be good and not bad IMO.
Using `array_udiff()` it is easy to diff $a and $b :
<?php
array_udiff($a, $b, array("cr", "comp_func_cr"));
?>

If there are better names for these functions I have nothing against to 
rename them. I named them this way because of the function `usort()` that 
sorts an array by using a callback function.

Regards,
Andrey

P.S.
I will appreciate the opinion of Marcus Boerger and Sebastian Bergmann 
whether these functions are useful or not. However, any other opinions 
are welcome (this is why i cross-post to internals@)



 >
 > ----- Original Message -----
 > From: "Andrey Hristov" <andrey@php.net>
 > To: <php-cvs@lists.php.net>
 > Sent: Tuesday, September 23, 2003 6:37 PM
 > Subject: [PHP-CVS] cvs: php-src /ext/standard array.c basic_functions.c
 > php_array.h
 >
 >
 >
> > […]
 >
 > function(s)
 >
> > […]
 `array_udiff_uassoc()`
> > […]
 >
 > values
 >
> > […]
 >
 > be
 >
> > […]
of a
> > […]
 >
 > test -
 >
> > […]
