-1

我已经尝试过此代码,但收到错误。

$queryfetch = 'select * from table';
    
$result = mysqli_query($connection, $queryfetch);
        
$row = mysqli_fetch_assoc($result);
        
$data = [];
foreach($row as $key) {
   $data[] = [
       'first_name' => $key['first_name'],
       'last_name' => $key['last_name']
    ];
}
        
echo json_encode($data);

如何使用 php 对特定键进行 json 编码?

4

1 回答 1

0

我已经解决了。。

$queryfetch = 'select * from table';
    
$result = mysqli_query($connection, $queryfetch);
        
$row = mysqli_fetch_assoc($result);

$data[] = array(
    'first_name' => $row['first_name'],
    'last_name' => $row['last_name']
);

echo json_encode($data);

这段代码运行良好..

于 2021-04-10T15:59:56.760 回答