如何仅在php中打印数组数据
我从查询结果中得到了这个返回值如何仅在php中打印数组数据,php,arrays,Php,Arrays,我从查询结果中得到了这个返回值 Array ( [0] => stdClass Object ( [password] => $2y$10$6D7S2gNkcDciJ7g5z/8sie79iV3FCGhGUCFCPHU3cNNdeUVUbLfQC ) ) 这是我的问题 $sql = "SELECT `$fields` FROM `$table` WHERE `$column` {$operator} '$value'"; if($this->_query = $this-&g
Array ( [0] => stdClass Object ( [password] => $2y$10$6D7S2gNkcDciJ7g5z/8sie79iV3FCGhGUCFCPHU3cNNdeUVUbLfQC ) )
这是我的问题
$sql = "SELECT `$fields` FROM `$table` WHERE `$column` {$operator} '$value'";
if($this->_query = $this->_pdo->prepare($sql)) {
if($this->_query->execute()) {
$this->_result = $this->_query->fetchAll(PDO::FETCH_OBJ);
$this->_count = $this->_query->rowCount();
} else {
return $this->_error = true;
}
}
print_r($this->_result);
现在,我只想显示或打印数组数据,这是$2y$10$6D7S2gNkcDciJ7g5z/8SIE79IV3FCGHGUCCFPHU3CNNDEUVULFQC
提前感谢您的帮助D可以使用方括号中的键访问数组元素,例如
$arr[$key]。
对象的属性可以使用->
操作符访问,例如$this->name
如果您只需要打印,这就足够了:
print\r($this->\u result[0]->password
) 你知道如何访问一个对象的属性和数组的值吗?如果你想让它使用$this->\u result[0]['password']
你应该使用PDO::FETCH\u ASSOC
。你想把对象转换成数组吗?我编辑了你的答案,因为print\r($this->\u result[0]->password)中没有缩进
但后来我发现您在密码
和)
之间有反勾号-因此我对您的原始答案进行了回滚。@Pengun如果您觉得答案对您有帮助,您可以接受它。:P