<p>What's the best algorithm for comparing two arrays to see if they have the same members?</p>

<p>Assume there are no duplicates, the members can be in any order, and that neither is sorted.</p>

<pre><code>compare(
    [a, b, c, d],
    [b, a, d, c]
) ==&gt; true

compare(
    [a, b, e],
    [a, b, c]
) ==&gt; false

compare(
    [a, b, c],
    [a, b]
) ==&gt; false
</code></pre>

The best I can think of is O(n^2), I guess.
```
```
function compare($foo, $bar) {
    if (count($foo) != count($bar)) return false;

    foreach ($foo as $f) {
        foreach ($bar as $b) {
            if ($f == $b) {
                // $f exists in $bar, skip to the next $foo
                continue 2;
            }
        }
        return false;
    }
    return true;
}
```
```