nathanjfield
nathanjfield

Reputation: 3

Parsing Multidimensional Array in PHP

Apologies if this is a duplication of another answer, I have spent a considerable amount of time looking through this and other forums without finding an explanation that makes sense to my very small brain.

I have a multi-dimensional array that I need to parse through using PHP:

Array
(
    [dataSetOut] => Array
        (
            [diffgram] => Array
                (
                    [anonymous] => Array
                        (
                            [maindb_productionhistory] => Array
                                (
                                    [0] => Array
                                        (
                                            [z_internal_sequence] => 1
                                            [z_internal_groupid] => 0
                                            [z_internal_colorbg] => 15461355
                                            [z_internal_colorfg] => 0
                                            [maindb_productionhistory_operation] => 0402D04
                                            [maindb_productionhistory_date] => 2014-02-19T00:00:00+00:00
                                            [maindb_productionhistory_shift] => 1
                                            [maindb_productionhistory_transcode] => 33
                                            [maindb_productionhistory_qty] => 153
                                            [!diffgr:id] => maindb_productionhistory1
                                            [!msdata:rowOrder] => 0
                                        )

                                    [1] => Array
                                        (
                                            [z_internal_sequence] => 2
                                            [z_internal_groupid] => 0
                                            [z_internal_colorbg] => 16777215
                                            [z_internal_colorfg] => 0
                                            [maindb_productionhistory_operation] => 0402D04
                                            [maindb_productionhistory_date] => 2014-02-19T00:00:00+00:00
                                            [maindb_productionhistory_shift] => 1
                                            [maindb_productionhistory_transcode] => 34
                                            [maindb_productionhistory_qty] => 6
                                            [!diffgr:id] => maindb_productionhistory2
                                            [!msdata:rowOrder] => 1
                                        )
                                )
                        )
                )
        )
    [errorMessage] => 
)

I am looking to output a table like:

Operation | Date | Qty

0402D04 | 2014-02-19 | 153

0402D04 | 2014-02-19 | 6

Upvotes: 0

Views: 61

Answers (1)

Daan
Daan

Reputation: 12236

<table>
<thead>
<tr>
<th>Operation</th>
<th>Date</th>
<th>Qty</th>
</tr>
</thead>
<tbody>
<?php
foreach($array['dataSetOut']['diffgram']['anonymous']['maindb_productionhistory'] as $val){
   echo "<tr>";
   echo "<td>".$val['maindb_productionhistory_operation']."</td>";
   echo "<td>".date('Y-m-d',strtotime($val['maindb_productionhistory_date']))."</td>";
   echo "<td>".$val['maindb_productionhistory_qty']."</td>";
   echo "</tr>";
 }
?>
</tbody>
</table>

Upvotes: 1

Related Questions