Two-way diff

Two-way diffs are the simplest diffs there are. It simply produces a change set between two documents. You can create two-way diffs by using the Differ class.

Examples

The example below shows a how to create a simple diff between two documents:

use CHItA\PHPDiff\DifferBase;
use CHItA\PHPDiff\Differ;

$differ = new Differ();
$diff = $differ->diff(
    array('a', 'b', 'b', 'a', 'c', 'b', 'b', 'a'),
    array('a', 'b', 'a', 'c', 'c', 'c', 'c', 'a', 'd')
);

// $diff will contain an array with the following structure:
//
// array(
//     array(
//          'type' => DifferBase::UNCHANGED,
//          array('a', 'b')
//     ),
//     array(
//          'type' => DifferBase::REMOVED,
//          array('b')
//     ),
//     array(
//          'type'  => DifferBase::UNCHANGED,
//          array('a', 'c')
//     ),
//     array(
//          array(
//              'type'  => DifferBase::REMOVED,
//              array('b', 'b')
//          ),
//          array(
//              'type'  => DifferBase::ADDED,
//              array('c', 'c', 'c')
//          )
//     ),
//     array(
//          'type'  => DifferBase::UNCHANGED,
//          array('a')
//     ),
//     array(
//          'type'  => DifferBase::ADDED,
//          array('d')
//     )
// )

Note

For more information about the diff structure generated by the library, please read the Diff structure section.