简体   繁体   中英

Php array to string conversion error with SLIM framework

I used a php framework to pass a variable $data to a html page the echo in loop here is my index.php :

$result=$db->query('select * from test');
while ($row=$result->fetch(PDO::FETCH_ASSOC)) {
  $data[]=$row;
}
$app->render('form.php',$data));

and then I display form.php

foreach ($this->$data as $user) {
  echo $user['id']. '-' . $user['name'].'<br>'
}

I get array to string conversion error, any idea ? I tired var_dump($this->$data); instead of the foreach loop and I get the same error : Array to string conversion

在此处输入图片说明

maybe $this->data instead of $this->$data

foreach ($this->$data as $user) {
  echo $user['id']. '-' . $user['name'].'<br>'
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM