Search code examples
phpmysqllamp

Unable to get an element from a php array when using MySQL


My goal here is to get the string out of the array that has been returned by PHP when using a MySQL database Select Statement. I know that the array is working fine because when I print_r I get

        stdClass Object ( [data] => 1 [name] => [array] => 6; )  

But when I try to get the array part with echo $row[0]['array']; the php interpreter fails at that line. How do I access the string [array] => 6; using the array notation?

Here is my attempt:

        $row = $result->fetch_object();
        //print_r($row);     
        echo $row[0]['array'];
        echo "<br/>";

Solution

  •     $row = $result->fetch_object();  
        echo $row->array;
        echo "<br/>";