fork download
  1. <?php
  2.  
  3. $a1 = '{
  4. "status": "success",
  5. "response": [
  6. {
  7. "id": "9",
  8. "name": "logo",
  9. "description": "Yo",
  10. "pack": "main"
  11. },
  12. {
  13. "id": "10",
  14. "name": "minus",
  15. "description": "Nope",
  16. "pack": "main"
  17. },
  18. {
  19. "id": "12",
  20. "name": "plus",
  21. "description": "Yep",
  22. "pack": "main"
  23. },
  24. {
  25. "id": "13",
  26. "name": "question",
  27. "description": "Where are you?",
  28. "pack": "main"
  29. },
  30. {
  31. "id": "14",
  32. "name": "rocket",
  33. "description": "Running late",
  34. "pack": "main"
  35. },
  36. {
  37. "id": "16",
  38. "name": "telephone",
  39. "description": "Call me back",
  40. "pack": "main"
  41. }
  42. ]
  43. }';
  44. $a1 = json_decode( $a1, true );
  45.  
  46. $a2 = '{
  47. "status": "success",
  48. "response": [
  49. {
  50. "id": "9",
  51. "name": "logo",
  52. "description": "Yo",
  53. "pack": "main"
  54. },
  55. {
  56. "id": "10",
  57. "name": "minus",
  58. "description": "Nope",
  59. "pack": "main"
  60. }
  61. ]
  62. }';
  63. $a2 = json_decode( $a2, true );
  64.  
  65. function udiffCompare($a, $b) {
  66. return $a['id'] - $b['id'];
  67. }
  68.  
  69. $arrdiff = array_udiff($a1['response'], $a2['response'], 'udiffCompare');
  70. print_r($arrdiff);
Success #stdin #stdout 0.02s 52472KB
stdin
Standard input is empty
stdout
Array
(
    [2] => Array
        (
            [id] => 12
            [name] => plus
            [description] => Yep
            [pack] => main
        )

    [3] => Array
        (
            [id] => 13
            [name] => question
            [description] => Where are you?
            [pack] => main
        )

    [4] => Array
        (
            [id] => 14
            [name] => rocket
            [description] => Running late
            [pack] => main
        )

    [5] => Array
        (
            [id] => 16
            [name] => telephone
            [description] => Call me back
            [pack] => main
        )

)