Embedding an array in PHP

Does anyone know of a diff diff implementation in PHP? I need to use this to develop a function similar to the stackexchange diffs method.

+6
source share
2 answers

As the documentation says:

Compares array 1 with one or more other arrays and returns values ​​in array 1 that are not present in any of the other arrays.

For instance:

$array1 = array("a" => "green", "red", "blue", "red"); $array2 = array("b" => "green", "yellow", "red"); $result = array_diff($array1, $array2); 

The result is a $result containing only the blue value, because it is in only one of the arrays.

Full documentation here: http://php.net/manual/en/function.array-diff.php

+1
source

There is diff_array that will compare the values ​​of 2 arrays and return an array with the difference values.

 $arrayone = array("bacon" => "tasty", "lettuce", "carrot"); $arraytwo = array("ham" => "tasty", "carrot"); $differences = array_diff($arrayone, $arraytwo); var_dump($differences); $differences = array_diff($arraytwo, $arrayone); var_dump($differences); 

This will give:

 array (size=1) 0 => string 'lettuce' (length=7) array (size=0) empty 

One important thing is only that the first array is compared with other passed ones.

http://php.net/manual/en/function.array-diff.php

0
source

Source: https://habr.com/ru/post/989109/


All Articles