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月19日T00: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月19日T00: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
-
I think your usage of the term "parse"is incorrect here. It sounds like you are just asking how to access the data in `$array['datasetOut']['diffgram']['anonymous']['maindb_productionhistory'], right? If that is that case, what is preventing you from simply access that array at that location?Mike Brant– Mike Brant2014年07月31日 14:05:23 +00:00Commented Jul 31, 2014 at 14:05
1 Answer 1
<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>
answered Jul 31, 2014 at 14:02
1 Comment
nathanjfield
Thanks Daan! <10 minutes not bad! :)
lang-php