title: PHP compare 2 different arrays by a value and find differences
body: <p>I have 2 very completely different arrays:</p>
  <p>1 looks like this ($fromBackend):</p>
  <pre><code>array:3 [
    114466 =&gt; array:1 [
      &quot;BrandID&quot; =&gt; 136,
      &quot;record&quot; =&gt; 114466
    ]
    114467 =&gt; array:1 [
      &quot;BrandID&quot; =&gt; 1,
      &quot;record&quot; =&gt; 114467
    ]
    114468 =&gt; array:1 [
      &quot;BrandID&quot; =&gt; 2,
      &quot;record&quot; =&gt; 114468
    ]
  ]
  </code></pre>
  <p>The other one looks like this ($fromFrontend):</p>
  <pre><code>array:2 [
    0 =&gt; Entity {#920
      #id: 117
      #brandId: 1
    }
    1 =&gt; Entity {#915
      #id: 118
      #brandId: 2
    }
  ]
  </code></pre>
  <p>Now as you can see I need to find the &quot;record&quot; of the first array where the brandId's dont match so in this case I need to find &quot;114466&quot; because BrandId =&gt; 136 doesn't exist in the second array</p>
  <p>Here's what I've got:</p>
  <pre><code>$recordsToDelete = [];
  foreach ($fromBackend as $fromBackendItem) {
      foreach ($fromFrontend as $fromFrontendItem) {
          if ($fromBackendItem['BrandID'] !== $brand-&gt;getBrandId()) {
              $recordsToDelete[] = $fromBackendItem['record'];
          }
      }
   }
  
   dd($recordsToDelete);
  </code></pre>
  <p>This gets me a weird results probably cause I am looping too much:</p>
  <pre><code>0 =&gt; 114466
  1 =&gt; 114466
  2 =&gt; 114467
  3 =&gt; 114468
  </code></pre>