dpxf81245
2014-10-24 14:32
浏览 8
已采纳

PHP数组 - 多维表分割

Dumb question. Below is my array. I got the first dimension to return to a table with a foreach loop, how do I iterate the 'work_order_status' part of the array to be able to set it into a table value?

Array
    (
        [transaction_id] => 2014102413362746N1SSCSYY9PFSUS85-0
        [response_code] => 200
        [work_order] => 151262
        [percent_complete] => 100
        [duplicate_records] => 0
        [work_order_status] => Array
            (
                [record] => Array
                    (
                        [0] => Array
                            (
                                [record_count] => 1590
                                [percent_of_total] => 40.52
                                [description] => Successful delivery
                            )

                        [1] => Array
                            (
                                [record_count] => 2
                                [percent_of_total] => .05
                                [description] => Invalid Number - too short
                            )

                        [2] => Array
                            (
                                [record_count] => 2
                                [percent_of_total] => .05
                                [description] => Invalid Number - Illegal NPA-NXX
                            )

                        [3] => Array
                            (
                                [record_count] => 2
                                [percent_of_total] => .05
                                [description] => Invalid Number - NULL submission
                            )

                        [4] => Array
                            (
                                [record_count] => 1
                                [percent_of_total] => .03
                                [description] => Invalid Number - Not a dialable number
                            )

                        [5] => Array
                            (
                                [record_count] => 996
                                [percent_of_total] => 25.38
                                [description] => Invalid Request - not a WIRELESS number
                            )

                        [6] => Array
                            (
                                [record_count] => 867
                                [percent_of_total] => 22.09
                                [description] => Max Account Retries Exceeded
                            )

                        [7] => Array
                            (
                                [record_count] => 18
                                [percent_of_total] => .46
                                [description] => Voicemail delivery unconfirmed
                            )

                        [8] => Array
                            (
                                [record_count] => 3
                                [percent_of_total] => .08
                                [description] => Voicemail played for 0 seconds
                            )

                        [9] => Array
                            (
                                [record_count] => 341
                                [percent_of_total] => 8.69
                                [description] => Voicemail played for less than message length.
                            )

                        [10] => Array
                            (
                                [record_count] => 18
                                [percent_of_total] => .46
                                [description] => No Answer
                            )

                        [11] => Array
                            (
                                [record_count] => 76
                                [percent_of_total] => 1.94
                                [description] => Network Disconnect (FEHU)
                            )

                        [12] => Array
                            (
                                [record_count] => 8
                                [percent_of_total] => .2
                                [description] => Duplicate Records
                            )

                    )

            )

    )
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dsg41888 2014-10-24 14:39
    已采纳

    You can use a foreach loop such as:

    foreach($array['work_order_status'] as $value) {
        //some code here
    }
    

    or if the ['record'] part of the array is actually the one you wanted to iterate over then you could do something like this:

    foreach($array['work_order_status']['record'] as $value) {
        //some code here
    }
    

    Edit after comments:

    foreach ($xml2['work_order_status']['record'] as $value)  {  
        echo "<td>" . $xml2 . "</td>" . 
        "<td>" . $value['record_count'] . "</td>" .
        "<td>" . $value['percent_of_total'] . "</td>" . 
        "<td>" . $value['description'] . "</td><tr>";
    }
    
    打赏 评论
  • dongyao4419 2014-10-24 16:47
    foreach ($xml2['work_order_status']['record'] as $key =>$value) { 
        echo "<td>" . $xml2 . "</td><td>" . $value['record_count'] . "</td><tr>" . "<td>" . $xml2 . "</td><td>" . $value['percent_of_total'] . "</td><tr>" . "<td>" . $xml2 . "</td><td>" . $value['description'] . "</td><tr>";
         }
    
    打赏 评论

相关推荐 更多相似问题