我從網(wǎng)站的json文件中獲取數(shù)據(jù)。這是來自URL的示例json數(shù)據(jù)。Array( [1] => TEXT1 [2] => Array ( [0] => Array ( [sample1] => text1 [sample2] => text2)))我已經(jīng)嘗試過使用此代碼。$json = file_get_contents('http://www.example.com/file.json');$datas = json_decode($json,true); foreach ($datas as $key => $row) { $data[] = $row; //unset($tempData[1]) foreach ($datas as $key2 => $row1) { $data1[] = $row1; unset($data1[0]); } }print_r($data1); exit;我想獲取第一個數(shù)組為TEXT1的數(shù)據(jù),另一個數(shù)組數(shù)據(jù)為sample1和sample2
2 回答

拉丁的傳說
TA貢獻1789條經(jīng)驗 獲得超8個贊
只是分享我對我的問題的回答及其當前的工作。
foreach ($datas as $row) {
$tempData = $row;
}
$json = json_encode($tempData);
$array = json_decode($json, true);
$lastArray = [];
foreach ($array as $key => $row1){
$lastArray[$key] = $row1;
}
- 2 回答
- 0 關(guān)注
- 152 瀏覽
添加回答
舉報
0/150
提交
取消