PHP code snippet to put mySQL query results into a 2 dimensional array

More often then not when I am are working with a mySQL database using PHP I want to put my results into a 2 dimensional array. A while back I found a snippet of code that very effectively does this. However, I am constantly digging through old projects trying to remember/find the piece the code that does this, So I figured I would post it here for reference. The code is only one line and will put the results of a mySQL query ($mySQLresults) into a 2 dimensional array.

 

while(($resultArray[] = @mysql_fetch_assoc($mySQLresults)) || array_pop($resultArray));

 

 

 

Source http://php.net/manual/en/function.mysql-fetch-assoc.php

Comments are closed.