How to convert php result set to array

藏色散人
Release: 2023-03-09 15:40:02
Original
2645 people have browsed it

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;
Copy after login
$result=$mysql_query("select `id` from table_a");
$ar=array();
while($rows=$mysql_fetch_array($result))
{
   $ar[] = rows['id'];//把id存放到数组里
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template