title: Php optimize double loop (array and object)
body: <p>I need optimization of loop (array) in loop (object). Below is my solution which is working, but if I try this with huge amount of data then is too slow.  </p>
  
  <p>Here is my array</p>
  
  <pre><code>$data = [
        ["PLZ", "Preis"],
        ["8074", "90"],
        ["8075", "90"],
        ["8076", "90"],
        ["8077", "90"],
        ["8078", "77"],
        ["1010", "77"],
        ["1020", "77"],
        ["1030", "77"],
        ["8041", "55"],
        ["8020", "89"],
      ];
  </code></pre>
  
  <p>Here is my object</p>
  
  <pre><code>$postal_collection = {
  "1010":1,
  "1020":2,
  "1030":3,
  "8020":1602,
  "8041":1604,
  "8074":1622,
  "8075":1623,
  "8076":1624,
  "8077":1625
  }
  </code></pre>
  
  <p>Here is working loop </p>
  
  <pre><code>$allData = [];
      foreach ($data as $key =&gt; $fields) {
        foreach ($postal_collection as $postal =&gt; $placeId) {
          if ($fields[0] == $postal) {
            $allData[$placeId] = [
              'postal' =&gt; $postal,
              'place_id' =&gt; $placeId,
              'price' =&gt; $fields[1],
            ];
          }
        }
      }
  </code></pre>
  
  <p>So how can I change this loop to make the same job but faster?</p>