PHP döngü optimizasyonu

0 Cevap

I have a php method that creates an HTML table with data it retrieves from a property. My biggest concern is the performance of my application because I deal with a large amount of data.

public function getHTML() {

    $phpObj =  json_decode($this->data); // array(object, object, object, ....);

    $table = "<table><tbody>\n";

    if (count($phpObj->query->results->row) > 0) {
        $row = $phpObj->query->results->row;

         foreach ($row as $value) {
            $table .= "<tr>\n";
            foreach ($value as $key => $val) { // concerned about loop inside loop
                $table .= "<td>" . $value->$key . "</td>"; 
            }
            $table .= "\n</tr>\n";
        }   

        $table .= "</tbody></table>";
        return $table;
    }
    else {
        return 'HTML table not created.';
    }       
}

Bir döngü içerisinde döngü yaratmadan dizi ve nesneler üzerinden geçme, daha verimli bir yolu var mı?

0 Cevap