PHP code example of wizaplace / collection-diff

1. Go to this page and download the library: Download wizaplace/collection-diff 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/ */

    

wizaplace / collection-diff example snippets




// Collection from your database
$from = [
    new FooObject("foo", "category1", 10.5),
    new FooObject("bar2", "category2", 9.5),
    new FooObject("bar1", "category1", 9.5),
    new FooObject("barFoo", "category1", 9.5),
    new FooObject("barFooBar", "category1", 9.5),
];

// Collection from you form like $_POST
$to = [
    [
        "name" => "foo",
        "category" => "category1",
        "price" => 11.5
    ],
    [
        "name" => "bar2",
        "category" => "category2",
        "price" => 9.5,
    ],
    [
        "name" => "bar1",
        "category" => "category2",
        "price" => 9.5,
    ],
    [
        "name" => "fooBar",
        "category" => "category3",
        "price" => 8.5,
    ],
];

$container
    ->get(\Wizaplace\CollectionDiff\CollectionDiff::class)
    ->compare(['name', 'category'], $from, $to, false, true)
    ->getActions();

$mySerializer = new FooSerializer();

$collectionDiff = new Wizaplace\CollectionDiff\CollectionDiff($mySerializer);
$collectionDiff->compare(['name', 'category'], $from, $to, false, true);

$collectionDiff->getActions();

// Or
$collectionDiff->getNothing();
$collectionDiff->getCreate();
$collectionDiff->getUpdate();
$collectionDiff->getDelete();