PHP数组-多维表拆分


PHP Array - Multi Dimension into table split

愚蠢的问题。下面是我的数组。我用foreach循环获得了返回到表的第一个维度,我如何迭代数组的"work_order_status"部分以将其设置为表值?

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

您可以使用foreach循环,例如:

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

或者,如果数组的['record']部分实际上是您想要迭代的部分,那么您可以执行以下操作:

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

评论后编辑:

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>";
}
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>";
     }