Skip to content

Latest commit

 

History

History
70 lines (50 loc) · 2.38 KB

README.md

File metadata and controls

70 lines (50 loc) · 2.38 KB

PHP Version : 8.5 License Tests
Source Packagist Version Packagist Downloads

Know exactly what changed in PHP data and text.

Added, removed, modified and moved values at their exact paths, records matched by ID, redacted secrets, and GitHub-style line diffs.

Installation

composer require pharaonic/php-diff

Usage

Compare two values

use Pharaonic\Diff\Diff;

$before = ['name' => 'Ali', 'age' => 30, 'phone' => '0100'];
$after  = ['name' => 'Ali', 'age' => 31, 'email' => 'ali@example.com'];

$result = Diff::between($before, $after);

$result->wasModified('age');   // true
$result->wasAdded('email');    // true
$result->wasRemoved('phone');  // true
$result->hasChanged('name');   // false

Compare two texts

echo Diff::text("apple\nbanana\ncherry\n", "apple\nblueberry\ncherry\n")->toUnified();
--- before
+++ after
@@ -1,3 +1,3 @@
 apple
-banana
+blueberry
 cherry

Guide

How to Compare Nested Arrays in PHP: Beyond array_diff()

Documentation

Full documentation: PHP Diff Documentation.

Support & Security

See SUPPORT.md and SECURITY.md.

License

MIT. See LICENSE.