php - 如何从 json 数组中获取所有定价值
问题描述
如何从 JSON 数组中获取所有定价值?我需要拆分两个段 tld(com、in、in.net 等)和相应的 tld 定价值我试图从数组中获取值,但 com、in 等这些是关键值。
我的 JSON 数组
Array
(
[result] => success
[pricing] => Array
(
[com] => Array
(
[categories] => Array
(
[0] => gTLD
[1] => Popular
)
[addons] => Array
(
[dns] => 1
[email] => 1
[idprotect] => 1
)
[group] => sale
[register] => Array
(
[1] => 637.70
)
[transfer] => Array
(
[1] => 637.70
)
[renew] => Array
(
[1] => 637.70
)
)
[in] => Array
(
[categories] => Array
(
[0] => ccTLD
[1] => Geography
)
[addons] => Array
(
[dns] => 1
[email] => 1
[idprotect] => 1
)
[group] => sale
[register] => Array
(
[1] => 1014.67
)
[transfer] => Array
(
[1] => 1014.67
)
[renew] => Array
(
[1] => 1014.67
)
)
[info] => Array
(
[categories] => Array
(
[0] => gTLD
[1] => Popular
)
[addons] => Array
(
[dns] => 1
[email] => 1
[idprotect] => 1
)
[group] => sale
[register] => Array
(
[1] => 200.00
)
[transfer] => Array
(
[1] => 200.00
)
[renew] => Array
(
[1] => 200.00
)
)
[net] => Array
(
[categories] => Array
(
[0] => gTLD
[1] => Popular
)
[addons] => Array
(
[dns] => 1
[email] => 1
[idprotect] => 1
)
[group] => sale
[register] => Array
(
[1] => 829.76
)
[transfer] => Array
(
[1] => 829.76
)
[renew] => Array
(
[1] => 829.76
)
)
[biz] => Array
(
[categories] => Array
(
[0] => gTLD
[1] => Popular
)
[addons] => Array
(
[dns] => 1
[email] => 1
[idprotect] => 1
)
[group] => sale
[register] => Array
(
[1] => 878.33
)
[transfer] => Array
(
[1] => 878.33
)
[renew] => Array
(
[1] => 878.33
)
)
[org] => Array
(
[categories] => Array
(
[0] => gTLD
[1] => Popular
)
[addons] => Array
(
[dns] => 1
[email] => 1
[idprotect] => 1
)
[group] => sale
[register] => Array
(
[1] => 939.45
)
[transfer] => Array
(
[1] => 939.45
)
[renew] => Array
(
[1] => 939.45
)
)
[asia] => Array
(
[categories] => Array
(
[0] => gTLD
[1] => ccTLD
[2] => Geography
[3] => Popular
)
[addons] => Array
(
[dns] => 1
[email] => 1
[idprotect] => 1
)
[group] => sale
[register] => Array
(
[1] => 1527.88
)
[transfer] => Array
(
[1] => 1527.88
)
[renew] => Array
(
[1] => 1527.88
)
)
[co.uk] => Array
(
[categories] => Array
(
[0] => ccTLD
[1] => Geography
)
[addons] => Array
(
[dns] => 1
[email] => 1
[idprotect] => 1
)
[group] => sale
[register] => Array
(
[1] => 602.53
)
[transfer] => Array
(
[1] => 602.53
)
[renew] => Array
(
[1] => 602.53
)
)
[in.net] => Array
(
[categories] => Array
(
[0] => Other
)
[addons] => Array
(
[dns] => 1
[email] => 1
[idprotect] => 1
)
[group] => sale
[register] => Array
(
[1] => 100.00
)
[transfer] => Array
(
[1] => 100.00
)
[renew] => Array
(
[1] => 100.00
)
)
[uk] => Array
(
[categories] => Array
(
[0] => ccTLD
[1] => Geographic
[2] => Popular
)
[addons] => Array
(
[dns] => 1
[email] => 1
[idprotect] => 1
)
[group] => sale
[register] => Array
(
[1] => 200.00
)
[transfer] => Array
(
[1] => 300.00
)
[renew] => Array
(
[1] => 400.00
)
)
)
)
如何拆分数组并从上述 JSON 数组中获取传输值?
解决方案
如果我没有误解您的问题,那么这就是您需要通过简单foreach()
循环来获取具有相应价格的tld
$expected = [];
foreach($result['pricing'] as $tld=>$array){
// this is the register value, you can change it for transfer or renew if you wish
$expected[$tld] = $array['register'][1];
}
print_r($expected);
推荐阅读
- sql - grafana - 添加新列
- r - dplyr 中空分组数据框/tibble 的构造函数
- java - 如何创建泛型类的新实例
- ansible - Ansible + LXC (Proxmox)
- react-native - 如何使用 react-test-renderer 和 jest 测试包含嵌套组件的反应组件,这些组件是连接组件?
- javascript - 如何使用时间戳 Dexie.js 而不是日期搜索在 2 小时或更短时间后删除 indexedDB
- html - 如何使用 vba 填写 html 自动完成字段?
- image-processing - 是否可以使用包含单个细胞的图像来训练模型以检测和定位测试图像中的多个细胞
- splunk - Splunk - 根据事件计数和事件数据获取预定义输出
- reactjs - 如何修复connected-react-router模块调用的导入错误?