mardi 4 août 2015

PHP: Why should we use array_udiff()?

I am trying to understand array_udiff() function. But Its confusing that both functions array_diff() and array_udiff() produces same results then why will we use array_udiff() ?

Code:

 echo "<h1>array_udiff()</h1>";
 $a = array('a'=>'apple', 'c'=>'cat', 'b'=>'book');
 $b = array('d'=>'dog');
 echo "<pre>";

 print_r(array_udiff($a,$b,function($a,$b){
  if ($a < $b) {
        return -1;
    } elseif ($a > $b) {
        return 1;
    } else {
        return 0;
    };
 }));


 echo "<h1>array_diff()</h1>";

 print_r(array_diff($a, $b));

Output:

Output

As you can see in above example that output of both functions are same then why should we use array_udiff() ?

Aucun commentaire:

Enregistrer un commentaire