PHP » PYTHON |
login |
register |
about
|
PYTHON array_diff
is this article helpful?
|
Python replacement for PHP's array_diff
[
edit
| history
]
Example:
>>> ["b","f","a","d"] - ["a","b","c"] ['d', 'f'] If order matters: >>> list1 = ["b", "f", "a", "d"] >>> list2 = ["a", "b", "c"] >>> [item for item in list1 if item not in list2] ['f', 'd'] array_diff(PHP 4 >= 4.0.1, PHP 5) array_diff — Computes the difference of arrays Description
array array_diff
( array $array1
, array $array2
[, array $ ...
] )
Compares array1 against array2 and returns the difference. Parameters
Return ValuesReturns an array containing all the entries from array1 that are not present in any of the other arrays. Examples
Example #1 array_diff() example
<?phpMultiple occurrences in $array1 are all treated the same way. This will output :
Array
(
[1] => blue
)
Notes
Warning
This was broken in PHP 4.0.4! See Also
|
more
Recently updated
more
Most requested
more
Last requests
|