gpt4 book ai didi

php - 将键更改为列并将值更改为值 php

转载 作者:行者123 更新时间:2023-12-05 07:29:36 25 4
gpt4 key购买 nike

数组是:

Array ( [0] => Array ( [dnu] => 121428 [d1] => 43 [d3] => 27 [d7] => 20 [d15] => 15 [d30] => 12 ) )

我想要这样的东西:

[{"col":"dnu","value":121428},{"col":"d1","value":"43"},{"col":"d7","value":"20"}]

最佳答案

试试这个。

$result = [];
foreach($array as $col => $value) {
$result[] = [
'col' => $col,
'value' => $value
];
}

$json = json_encode($result);

关于php - 将键更改为列并将值更改为值 php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52658301/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com