Using array_diff

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
JeffG
Forum Commoner
Posts: 35
Joined: Wed Jan 30, 2008 1:42 pm
Location: Newbury, UK

Using array_diff

Post 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.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Using array_diff

Post 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.
JeffG
Forum Commoner
Posts: 35
Joined: Wed Jan 30, 2008 1:42 pm
Location: Newbury, UK

Re: Using array_diff

Post by JeffG »

Many thanks! How simple is that?
Post Reply