PHP Classes

File: README.md

Recommend this page to a friend!
  Classes of Niko   PHP Array Diff Multidimensional   README.md   Download  
File: README.md
Role: Documentation
Content type: text/markdown
Description: Documentation
Class: PHP Array Diff Multidimensional
Get differences between 2 multidimensional arrays
Author: By
Last change:
Date: 5 years ago
Size: 1,099 bytes
 

Contents

Class file image Download

Array Diff Multidimensional

Based on PHP array_diff() function, but will have support for multidimesional arrays. PHP.net Bug report.

Install

Via composer:

composer require niko9911/diff-multidimensional-array

Usage

Will work like normal PHP array_diff_assoc($new, $old, $older). Basic usage is following:

Multidimensional::diff(array $array1 , array $array2 [,array $...]): array

Example:

<?php
declare(strict_types=1);
use Niko9911\ArrayDiff\Multidimensional;


$newResults = [
	'zoo' => 'pets',
	'foo' => [
        'cat',
        'dog',
        'php'
	],
];

$oldResults = [
	'zoo' => 'pets',
	'foo' => [
        'php'
	],
];

var_dump(Multidimensional::diff($new,$old));
/ Will result:
  array(1) {
    'foo' =>
    array(3) {
      [0] =>
      string(3) "cat"
      [1] =>
      string(3) "dog"
      [2] =>
      string(3) "php"
    }
  }
 */

License

Licensed under the MIT license.