php curl 中仅显示 1 条数据
Showing only 1 piece of data in php curl
MY JSON FILE 获取 json 文件
{
"isSuccess": true,
"data": {
"usersType": 1,
"users": [
{
"uid": 1,
"unumber": 2,
"utel": 265954452,
"un": "Cedric",
"ul": "Williams",
"ucid": 1,
"uregdate": "2020-07-01T22:45:00",
"ed": 15,
"uregdates": "July Wednesday 1",
"edh": "22:45",
"en": "Admin",
"mb": null,
"admin": true,
"mc": 0,
"userticketid": 22419949
},
{
"uid": 2,
"unumber": 2,
"utel": 16595197,
"un": "Michael",
"ul": "Lovato",
"ucid": 2,
"uregdate": "2020-07-02T15:00:00",
"ed": 159,
"uregdates": "July Thursday 2",
"edh": "15:00",
"en": "User",
"mb": null,
"admin": false,
"mc": 0,
"userticketid": 52638722
}
]
},
"message": "",
"error": null,
"info": null,
"date": null
}
我的 PHP 文件使用 curl
$url = 'http://localhost/json';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
curl_close($ch);
$result_arr = json_decode($result);
foreach($result_arr->data->users as $ok)
{
$uid = $ok->uid;
$un = $ok->un;
$en = $ok->en;
$uregdates = $ok->uregdates;
$uregdate = $ok->uregdate;
$userticketid = $ok->userticketid;
}
echo $id." ".$un." ".$en." ".$uregdates." ".$uregdate." ".$userticketid;
仅显示 1 条数据,我想要“usersType”: 1, > go show list “users”: []
我想要全部回显所有变量。请问你能帮我吗
问题在哪里?你能帮我找到吗
我尝试了各种方法。卷曲功能失败
你能把它完整地列出来吗?
我会画很多数据
您的 echo
应该在 foreach
循环内。应该是这样
foreach($result_arr->data->users as $ok) {
$uid = $ok->uid;
$un = $ok->un;
$en = $ok->en;
$uregdates = $ok->uregdates;
$uregdate = $ok->uregdate;
$userticketid = $ok->userticketid;
echo $uid." ".$un." ".$en." ".$uregdates." ".$uregdate." ".$userticketid;
}
MY JSON FILE 获取 json 文件
{
"isSuccess": true,
"data": {
"usersType": 1,
"users": [
{
"uid": 1,
"unumber": 2,
"utel": 265954452,
"un": "Cedric",
"ul": "Williams",
"ucid": 1,
"uregdate": "2020-07-01T22:45:00",
"ed": 15,
"uregdates": "July Wednesday 1",
"edh": "22:45",
"en": "Admin",
"mb": null,
"admin": true,
"mc": 0,
"userticketid": 22419949
},
{
"uid": 2,
"unumber": 2,
"utel": 16595197,
"un": "Michael",
"ul": "Lovato",
"ucid": 2,
"uregdate": "2020-07-02T15:00:00",
"ed": 159,
"uregdates": "July Thursday 2",
"edh": "15:00",
"en": "User",
"mb": null,
"admin": false,
"mc": 0,
"userticketid": 52638722
}
]
},
"message": "",
"error": null,
"info": null,
"date": null
}
我的 PHP 文件使用 curl
$url = 'http://localhost/json';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
curl_close($ch);
$result_arr = json_decode($result);
foreach($result_arr->data->users as $ok)
{
$uid = $ok->uid;
$un = $ok->un;
$en = $ok->en;
$uregdates = $ok->uregdates;
$uregdate = $ok->uregdate;
$userticketid = $ok->userticketid;
}
echo $id." ".$un." ".$en." ".$uregdates." ".$uregdate." ".$userticketid;
仅显示 1 条数据,我想要“usersType”: 1, > go show list “users”: []
我想要全部回显所有变量。请问你能帮我吗 问题在哪里?你能帮我找到吗 我尝试了各种方法。卷曲功能失败 你能把它完整地列出来吗? 我会画很多数据
您的 echo
应该在 foreach
循环内。应该是这样
foreach($result_arr->data->users as $ok) {
$uid = $ok->uid;
$un = $ok->un;
$en = $ok->en;
$uregdates = $ok->uregdates;
$uregdate = $ok->uregdate;
$userticketid = $ok->userticketid;
echo $uid." ".$un." ".$en." ".$uregdates." ".$uregdate." ".$userticketid;
}