Skip to content
Advertisement

PHP: Built-in function to check whether two Array values are equal ( Ignoring the order)

Is there a built-in function for PHP for me to check whether two arrays contain the same values ( order not important?).

For example, I want a function that returns me true for the following two inputs:

JavaScript

Edit: I could have sorted the two arrays and compare them, but as I am such a lazy guy, I would still prefer a one-liner that I can pull out and use.

Advertisement

Answer

array_diff looks like an option:

JavaScript

or as an oneliner in your code:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement