PHP code example of ridvanaltun / json-patch-generator

1. Go to this page and download the library: Download ridvanaltun/json-patch-generator library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ridvanaltun / json-patch-generator example snippets




idvanaltun\JsonPatchGenerator\Utils;

$utils = new Utils();

$oldSnap = [
  'name'    => 'foo',
  'surname' => 'bar',
  'skils'   => [
    'computer_science' => true,
    'algorithm'        => true,
    'math'             => false,
  ],
  'specs'   => [
    'a',
    'b',
    'c',
  ]
];

$currSnap = [
  'name'  => 'foo',
  'age'   => 23,
  'skils' => [
    'computer_science' => true,
    'algorithm'        => false,
  ],
  'specs' => [
    'a',
    'b',
    'd',
    'e',
  ]
];

$jsonPatch = $utils->generateJsonPatch($currSnap, $oldSnap);

var_dump($jsonPatch);