db->get();"; then pass "while($value = $row->fetch_array()) {$result[] =$value;}" can be converted into an array."/> db->get();"; then pass "while($value = $row->fetch_array()) {$result[] =$value;}" can be converted into an array.">

Home  >  Article  >  Backend Development  >  How to convert php result set to array

How to convert php result set to array

藏色散人
藏色散人Original
2021-05-11 09:48:412625browse

How to convert php result set to array: first get the object result set through "$this->db->get();"; then use "while($value = $row-> fetch_array()) {$result[]=$value;}" can be converted into an array.

How to convert php result set to array

The operating environment of this article: Windows 7 system, PHP version 7.1, DELL G3 computer

PHP queries the database, and the object result set is converted into an array

$row = $this->db->get();//得出对象结果集
$result = array();
if($row) {
    //转化为数组
   while($value = $row->fetch_array()) {
            $result[] = $value;
     }
}
print_r($result);eixt;
return $result;
$result=$mysql_query("select `id` from table_a");
$ar=array();
while($rows=$mysql_fetch_array($result))
{
   $ar[] = rows['id'];//把id存放到数组里
}

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to convert php result set to array. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn