简体   繁体   English

PHP数组到SLIM框架的字符串转换错误

[英]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 : 我使用了php框架将变量$ data传递到html页面,循环中的回显是我的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 然后我显示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); 我累了var_dump($this->$data); instead of the foreach loop and I get the same error : Array to string conversion 而不是foreach循环,我得到了相同的错误:数组到字符串的转换

在此处输入图片说明

maybe $this->data instead of $this->$data 也许$ this-> data而不是$ this-> $ data

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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