Fetch result of query twice I faced with problem while fetching query results, my code:

$result = $query-&gt;execute();
$array1 = $result-&gt;fetchAllKeyed(1, 0);
$array2 = $result-&gt;fetchAllKeyed(2, 0);


But the $array2 is empty, so fetchAllKeyed cut all values from $result.

I'm already tried to use the following:

$query2 = clone $query;
$result = $query-&gt;execute();
$result2 = $query2-&gt;execute();
$array1 = $result-&gt;fetchAllKeyed(1, 0);
$array2 = $result2-&gt;fetchAllKeyed(2, 0);


It's works, but I don't want do two queries instead of one.

So, how can I do two (or more) different "fetch" from one result?
Since fetchAllKeyed() internally uses foreach loop to sort the data, the answer given by  Suranga Panagamuwa Gamage to use fetchAssoc() and then a loop seems the most efficient way.