Quote:
Originally Posted by DustyPorViva
Is there a simple way to compare two arrays like so:
PHP Code:
array1 = {1,1};
array2 = {2,2};
if (array1 == array2)
Without running loops? Ideally I'm looking for a single if check like my example, but my attempts have proven unsuccessful. Is there one of those 'secrets' or is it just not possible?
|
No, it's not possible. If you want to check every item in the array you'll need to loop through it, although you can break the loop once it returns false.
The conversion to a string with
@ does a loop internally to concatenate all the items, which would probably be faster since it's native, however, it could get slower as your array gets larger because in your implementation it'll stop looping once you hit a difference.
If you just want to check if all the items are the same, rather than in the same order, I would do what Crow said and run a sort on them (probably
TGraalVar.sortascending() would be the fastest). If you have a HUGE array, then you could also use the
introsort I wrote awhile back and it would probably perform better than
sortascending().