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:
array('4','5','2')
array('2','4','5')
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.
array(1, 2, 3)vsarray(1, 2, 3, 1)? Some of the answers will return true, others false. Also, some will return inconsistent results due to short-circuiting via count(), and will return false in the first example but true if comparingarray(1, 2, 3, 1)witharray(1, 2, 3, 2). My guess is that this doesn't apply in your situation, but for anyone looking for an answer where duplicate entries may exist, care must be taken to use an algorithm that meets your specific requirements.