0

I am storing two sets of json data into two different columns in sql.

I am needing the compare the two strings, then highlight the string that is different. (I first tried to place the items into an array and then an array diff, doesn't deliver what I need)

Here is the first string {"Pri_ID":"340","SanctionID":"55555","PersonID":"387097","Type":"Athlete","OrgID":"253001","EntryDate":"2013-04-10"},{"Pri_ID":"349","SanctionID":"111222","PersonID":"497625","Type":"Athlete","OrgID":"253001","EntryDate":"2013-04-10"},{"Pri_ID":"334","SanctionID":"111111","PersonID":"420495","Type":"Athlete","OrgID":"253001","EntryDate":"2013-04-10"}"

here is the second string {"Pri_ID":"337","SanctionID":"111222","PersonID":"497625","Type":"Athlete","OrgID":"253001","EntryDate":"2013-04-10"},{"Pri_ID":"341","SanctionID":"111111","PersonID":"420495","Type":"Athlete","OrgID":"253001","EntryDate":"2013-04-10"},

as you can see there is a record / string deleted from the second string. I need to show the string that has been deleted.

Here is what I have done so far:

if (strcmp($str1, $str2)) {
    echo $str2;
}

this doesnt not strip everything else out and show the string

What have you tried
  • 11,018
  • 4
  • 31
  • 45
Matthew Colley
  • 10,816
  • 9
  • 43
  • 63

1 Answers1

2

Since this is array of JSONs you can first explode it (you can do it by new line char) to put every JSON in array and then do json_decode() for each of them. Then you will get two arrays which will consist of associative arrays. All you have to do is to make the loops and compare if one array contains the other one and put the missing ones into third array.

Hope this helps...

Goran
  • 3,292
  • 2
  • 29
  • 32