Skip to content

Latest commit

 

History

History
69 lines (49 loc) · 2.24 KB

README.md

File metadata and controls

69 lines (49 loc) · 2.24 KB

PHP Version : 8.6 License Build
Source Packagist Version Packagist Downloads

Know exactly what changed in PHP data and text.


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.