Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
200 views
in Technique[技术] by (71.8m points)

php - Get values of variations in a loop from json output

it seems I cant get this one. I am trying to get a loop from this json output. My aim is the variation values to be separated from the group:

Array
(
    [response_description] => 000
    [content] => Array
        (
            [ServiceName] => Gotv Payment
            [serviceID] => gotv
            [convinience_fee] => N0.00
            [varations] => Array
                (
                    [0] => Array
                        (
                            [variation_code] => gotv-lite
                            [name] => GOtv Lite N410
                            [variation_amount] => 410.00
                            [fixedPrice] => Yes
                        )

                    [1] => Array
                        (
                            [variation_code] => gotv-max
                            [name] => GOtv Max N3,600
                            [variation_amount] => 3600.00
                            [fixedPrice] => Yes
                        )

                    [2] => Array
                        (
                            [variation_code] => gotv-jolli
                            [name] => GOtv Jolli N2,460
                            [variation_amount] => 2460.00
                            [fixedPrice] => Yes
                        )

                    [3] => Array
                        (
                            [variation_code] => gotv-jinja
                            [name] => GOtv Jinja N1,640
                            [variation_amount] => 1640.00
                            [fixedPrice] => Yes
                        )

                    [4] => Array
                        (
                            [variation_code] => gotv-lite-3months
                            [name] => GOtv Lite (3 Months) N1,080
                            [variation_amount] => 1080.00
                            [fixedPrice] => Yes
                        )

                    [5] => Array
                        (
                            [variation_code] => gotv-lite-1year
                            [name] => GOtv Lite (1 Year) N3,180
                            [variation_amount] => 3180.00
                            [fixedPrice] => Yes
                        )

                )

        )

)

I tried this and I got the values, but they are in a group, I need them separated in a loop of as in the json output for 0, 1, etc

Here is what I tried:

    $array = json_decode($result, true);
 //echo '<pre>';print_r(json_decode($result,TRUE)); 

 foreach ($array as $key => $jsons) { // This will search in the 2 jsons
     foreach($jsons as $key => $varations) {
        foreach($varations as $key => $loop) {
            foreach($loop as $key => $value) {
         echo $value; 
         echo "<br><br>";
       }
     }
    }
}

And got this:

gotv-lite

GOtv Lite N410

410.00

Yes

gotv-max

GOtv Max N3,600

3600.00

Yes

gotv-jolli

GOtv Jolli N2,460

2460.00
gotv-lite

GOtv Lite N410

410.00

Yes

gotv-max

GOtv Max N3,600

3600.00

Yes

gotv-jolli

GOtv Jolli N2,460

2460.00

Please someone help your friend. Thanks


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...