title: Is there a faster way to compare multiple arrays in PHP?
body: <p>I have a slow performance issue in comparing multiple arrays. </p>
  
  <p>The algorithm that I've made is: </p>
  
  <p>I'll be looping first the arrays by foreach</p>
  
  <pre class="lang-php prettyprint-override"><code>foreach($branches as $index =&gt; $branch) {
      if (!$identical) {
          continue;
      }
  
      // Basically this $permissions will be fetching data from the database.
      $permissions = $this-&gt;get()
          -&gt;where('user_id', $userId)
          -&gt;where('branch_id', $userBranchId)
          -&gt;sortBy('permission_id')
          -&gt;pluck(['permission_id']);
  
      // if index = 0 then I'll initialize the temporary variable (ARRAY) $initial otherwise I'll compare two variable (ARRAY)
      if ($index === 0) {
          $initial = $permissions;
      } else {
          if ($initial != $permissions) {
              $identical = false;
          }
      }
  }
  </code></pre>
  
  <p>So to compare multiple arrays, I use only this if condition and comparative symbol (==). But I'm thinking if</p>