Page 1 of 1

Using array_diff

Posted: Thu May 07, 2009 4:44 am
by JeffG
I find the documentation for array_diff and all its variants pretty confusing.

What I want to do is compare two rows in the same table of a MySql database and say whether they are identical or not (apart from the primary key, of course). Is there an easy way to do this using array_diff? Other than that, I would need to extract each row with a different prefix and compare columns individually.

Thanks.

Re: Using array_diff

Posted: Thu May 07, 2009 5:26 am
by requinix
No need for a function.

Get the two rows of data into PHP. Use unset to remove the primary keys from both; then a simple

Code: Select all

if ($array1 == $array2)
will do the trick.

Re: Using array_diff

Posted: Thu May 07, 2009 5:48 am
by JeffG
Many thanks! How simple is that?