Create a 2D array from SQL table
This comment lies.


$sql = "SELECT * FROM $table"; // get a list of all fields and datatypes (ignore the latter)



You copy pasted the whole line and then neglected to update/remove the comment.
It's traditional to use a simple i for loop counter variables. I see no reason to use a triple iii or jjj. However, in this case it makes much more sense to use more verbose (and hence, descriptive) names like $row and $col.