title: How to get result for each element in array using PDO::fetchAll()?
body: <p>I have an array with id's and I want to get result for each id from pgsql db. But I dont want to make multiple requests like</p>
  <pre><code>$array = [1,2,3,4,5];
  foreach ($array as $a) {
      $result[$a] = $pdo-&gt;add('SELECT * FROM table WHERE id = ' . $a)-&gt;execute()-&gt;fetchAll();
  }
  </code></pre>
  <p>I want something like</p>
  <pre><code>$array = [1,2,3,4,5];
  $pl = '(' . implode(',', array_fill(0, count($array), '?')) . ')';
  $result = $pdo-&gt;add('SELECT * FROM table WHERE id IN ' . $pl)-&gt;execute($array)-&gt;fetchAll();
  </code></pre>
  <p>But the problem is, if there are 10 id but only 7 records from request, I cannot determine which records belong to which id.</p>
  <p>I want to make one request to db and get results like this, is there any options?</p>
  <pre><code>$data = [
      ['id' = 1, 'ok' = 1],
      ['id' = 2, 'ok' = 1],        
      ['id' = 3, 'ok' = 0],
      ['id' = 4, 'ok' = 0],
      ['id' = 5, 'ok' = 1],
  ]
  $keys = [1,2,3,4,5];
  $res = $pdo-&gt;add('SELECT id FROM table WHERE ok = 1')-&gt;execute()-&gt;fetchAll();
  
  //Result
  $res = array(
      [1] =&gt; 1
      [2] =&gt; 2
      [3] =&gt; null
      [4] =&gt; null
      [5] =&gt; 5
  )
  </code></pre>