Re: Re: unexpected array_diff output
| From: | Torsten Roehr | Date: | Fri, 30 Apr 2004 09:31:17 +0000 |
| Subject: | Re: Re: unexpected array_diff output | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-185028@lists.php.net to get a copy of this message | ||
"Frederic Noyer" <phphraban@noyer.ch> wrote in message
news:3AE4478C-9A88-11D8-B06A-000A95A78AFC@noyer.ch...
>
> On 30 avr. 04, at 11:00, Torsten Roehr wrote:
> >>
> >
> > I think this is correct because the 3 key/value pairs from the first
> > array
> > are NOT in the second one. I think the combination of key and value are
> > relevant for array_diff().
>
> As I have understand only the array_diff_assoc function does that.
> see php.net:
>
> "Description
> array array_diff_assoc ( array array1, array array2 [, array ...])
>
> array_diff_assoc() returns an array containing all the values from
> array1 that are not present in any of the other arguments. Note that
> the keys are used in the comparison unlike array_diff()."
So array_diff() seems to be for arrays where the key is not defined so that
only values are recognized.
Regards, Torsten
>
> Fred
> >
> > So if you had:
> >
> > Array from POST: Array ( [0] => 2 [1] => 3 [2] => 4 )
> > Array from SQL : Array ( [0] => 2 [1] => 3 )
> > ******
> >
> > The diff would be:
> > array_diff results : Array ( [2] => 4 )
> >
> > Regards, Torsten