作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我试图返回一个从存储在 PHP 文件中的公共(public)函数调用的数组。我需要导出的返回数组是 JSON 格式。我有下面的代码用于调用数组(在其他情况下有效),但输出只是数组(phpMyAdmin 中的 sql 返回所有数据)
这是应该返回数组的公共(public)函数,该数组存储在通用 PHP 类文件中。
public function getIssueList() {
$sql = "select * from IssueData";
$returnValue = array();
$result = $this->conn->query($sql); // makes the connection and executes the sql
if ($result != null) {
$row = $result->fetch_array(MYSQLI_ASSOC);
if (!empty($row)) {
$returnValue = $row;
}
}
return $returnValue;
}
然后我从下面的代码中调用公共(public)函数:
$result = $dao->getIssueList(); //opens the connection and calls the public function
echo $result;
但是我得到的回显结果只是“Array”这个词
上面的代码适用于其他公共(public)函数,但它只返回一行,而不是我在本例中需要的多行。我还需要将数组设为关联数组。
可能出了什么问题?
最佳答案
您可以 json_encode ( http://php.net/manual/en/function.json-encode.php )
echo json_encode($result);
关于php - 如何在 PHP 中返回从 MySQL 获取的数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33724810/
我是一名优秀的程序员,十分优秀!