php - How to loop an array by passing it an object in the foreach

one text

Solution:

As I understand, $tableFields is an array so you have to iterate through it as well. So try this for your foreach loop.

foreach ($res as $r){
    $html .= '<tr>';
    foreach($myObject->tableFields as $field){
        $html .= '<td>' . $r->$field . '</td>'; 
    }
    $html .= '</tr>';
}

Source