第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用未知數量的 json 循環(huán)創(chuàng)建多維關聯(lián)數組

使用未知數量的 json 循環(huán)創(chuàng)建多維關聯(lián)數組

PHP
動漫人物 2021-08-28 15:27:39
所以,我正在接收 json 輸入。我不知道我會收到多少輸入。我知道如何將其轉換為數組,但是我需要混淆數組的結構。數組目前是多維的,并且已經是關聯(lián)的,但是使用了錯誤的關聯(lián)。對我來說,它使用“標簽”和“值”,但我需要將這兩個放在一個使用“x”和“y”的關聯(lián)數組中,以便我可以在圖表中使用它們。示例 json{    "metingen": [        {            "label": "06-06-2019 13:13:38",            "value": 25.21        },        {            "label": "06-06-2019 13:51:04",            "value": 27.69        },        {            "label": "06-06-2019 13:52:04",            "value": 27.69        },        {            "label": "06-06-2019 13:53:06",            "value": 27.61        },        {            "label": "06-06-2019 13:54:08",            "value": 27.56        },        {            "label": "06-06-2019 13:55:08",            "value": 27.55        },        {            "label": "06-06-2019 13:56:09",            "value": 27.55        },        {            "label": "06-06-2019 13:57:09",            "value": 27.53        },        {            "label": "06-06-2019 14:05:12",            "value": 28.51        },        {            "label": "06-06-2019 14:06:12",            "value": 28.53        },        {            "label": "06-06-2019 14:07:13",            "value": 28.51        },        {            "label": "06-06-2019 14:08:13",            "value": 28.51        },        {            "label": "06-06-2019 14:09:14",            "value": 28.53        },        {            "label": "06-06-2019 14:10:14",            "value": 28.52        },        {            "label": "06-06-2019 14:11:15",            "value": 28.52        },        {            "label": "06-06-2019 14:12:15",            "value": 28.54        },        {            "label": "06-06-2019 14:13:16",            "value": 28.53        },        {            "label": "06-06-2019 14:14:16",            "value": 28.48        },        {            "label": "06-06-2019 14:15:17",            "value": 28.39        },        {            "label": "06-06-2019 14:16:17",            "value": 28.37        }    ],    "title": "Temperature for ICT Boven"}
查看完整描述

2 回答

?
弒天下

TA貢獻1818條經驗 獲得超8個贊

您可以將 array_map 與 array_combine 一起使用,如下所示,


$temp['metingen'] = array_map(function ($item) {

    return array_combine(['x', 'y'], $item); // x and y are keys and label and value are values

}, $temp['metingen']);


查看完整回答
反對 回復 2021-08-28
?
慕容708150

TA貢獻1831條經驗 獲得超4個贊

你可以用foreach與json_decode


$jToArr = json_decode($json, true);

$res = [];

foreach($jToArr['metingen'] as $key => $value){

  $res[] = ['x' => $value['label'], 'y' => $value['value']];

}

print_r($res);


查看完整回答
反對 回復 2021-08-28
  • 2 回答
  • 0 關注
  • 122 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號