Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Array diff implementation in PHP [closed]

Tags:

algorithm

php

Does anybody know of an array diff implementation in PHP? I need to use this to develop a feature similar to the way stackexchange diffs tags.

like image 983
Taylor Conaugh Avatar asked Jun 15 '15 05:06

Taylor Conaugh


1 Answers

Like the documentation says:

Compares array1 against one or more other arrays and returns the values in array1 that are not present in any of the other arrays.

For example:

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

Would end up with $result containing only the value blue, because it is only in one of the arrays.

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

like image 190
Peter Avatar answered Oct 13 '22 20:10

Peter