The word “Array” gets printed instead of the value

2019-01-20 13:55发布

问题:

Okay,i'm a newbie to CI and MySQL. This is my code:

<?php
class Trail2 extends CI_Controller{

public function boo() {

    $this->load->database();
    $this->load->helper('html');
    $ret="SELECT * from posts";
    $query=$this->db->query($ret);
    foreach($query->result_array() as $row)
    {
        echo br(1);
        echo $row;
    }   
}

}

?>

and this returns the word "Array" in place of the values of the rows. I cant seem to figure out why though. Thanks in advance. :)

回答1:

use

var_dump($row);

instead of

echo $row;

and if you just want to see the values of the array you can do something like the following

for ($var = 0; $var < sizeof($row); $var++) echo $row[$var].", ";


回答2:

$row is an array. use $row['column'] to access a single column. to see what the array looks like, you can use print_r($row) or var_dump($row)