以下是一个简单的PHP接口返回实例,通过表格形式展示数据格式:
| 字段名 | 类型 | 说明 |
|---|---|---|
| status | int | 状态码,1表示成功,0表示失败 |
| message | string | 返回信息,描述成功或失败原因 |
| data | array | 返回的数据,包含所需的具体信息 |
| -id | int | 主键ID |
| -name | string | 名称 |
| -age | int | 年龄 |
| string | 邮箱 |
PHP接口返回示例代码
```php

header('Content-Type: application/json');
// 模拟数据
$data = [
'id' => 1,
'name' => '张三',
'age' => 25,
'email' => 'zhangsan@example.com'
];
// 根据业务逻辑,设置状态码和信息
if ($data) {
$response = [
'status' => 1,
'message' => '获取数据成功',
'data' => $data
];
} else {
$response = [
'status' => 0,
'message' => '获取数据失败,请重试'
];
}
echo json_encode($response);
>
```
返回结果示例
```json
{
"







