如何从我的 PHP 数组 (mysql_fetch_array) 转换为声明的 PHP 类,然后将其编码为 json 格式字符串。我的数组:
while ($rows = mysql_fetch_array($result, MYSQL_ASSOC)){
$patient[] = array( 'id' => $rows['id'],
'name' => $rows['name'],
'sex' => $rows['sex'],
'civil_status' => $rows['civil_status'],
'age' => $rows['age'],
'type_of_admission' => $rows['type_of_admission'],
'admission_diagnosis' => $rows['admission_diagnosis'],
'date_admitted' => $rows['date_admitted']);
}
我的声明 PHP 类
class Person
{
public $id;
public $name;
public $sex;
public $civil_status;
public $age;
public $type_of_admission;
public $admission_diagnosis;
public $date_admitted;
}