2D array with column names is what query with MYSQLI_ASSOC already returns - no need to use separate query for these names. Also note $array[]
notation inside while loop - equivalent for array_push() function. Try this:
$sql = "SELECT * FROM $table";
$res = mysqli_query($conn, $sql);
while ($row = mysqli_fetch_array($res, MYSQLI_ASSOC)) {
$tableContent[] = $row;
}
While
loop might be replaced with:
$tableContent = mysqli_fetch_all($res, MYSQLI_ASSOC);
but it's problematic with large result sets (like dumping entire table) and further processing it would require a loop anyway.