【问题标题】:How to get the all the pricing value from the json array如何从 json 数组中获取所有定价值
【发布时间】:2018-10-27 21:12:38
【问题描述】:

如何从 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数组中获取传输值?

【问题讨论】:

  • 预期的输出数组是什么?
  • 价格是多少?你想要的输出是什么?你尝试过什么失败了?

标签: php arrays json laravel


【解决方案1】:

如果我没有误解您的问题,那么这就是您需要通过简单的 foreach() 循环来获取 tlds 及其相应的价格 >

$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);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-01-18
    • 2021-12-18
    • 1970-01-01
    • 2016-01-18
    • 2013-04-11
    • 2017-07-09
    • 1970-01-01
    相关资源
    最近更新 更多