我有这个对象:

stdClass Object
(
[daily_inventoryID] => 1
[inventory_timestamp] => 2012-06-08 14:35:42
[inventory_date] => 2012-06-08
[inventory] =>
Array
(
[0] => stdClass Object
    (
        [ingredientID] => 2
        [code] => Bf
        [description] => 1st Class Flour
        [volume] => 8268
        [price] => 750
        [amount_gram] => 0.02980
        [status] => Inactive
        [uom_id] => 1
        [flour] => Yes
    )

[1] => stdClass Object
    (
        [ingredientID] => 3
        [code] => Sf
        [description] => 3rd Class Flour
        [volume] => 18490
        [price] => 635
        [amount_gram] => 0.02540
        [status] => Inactive
        [uom_id] => 5
        [flour] => Yes
    )
...........


假设我们将对象命名为$ inv,我想显示$ inv-> inventory的值,该值是包含对象的数组。

我将如何使用foreach或for循环来做到这一点?

最佳答案

foreach ($inv->inventory as $inventory) {
  print_r($inventory);
}

关于php - 用对象数组制作表格,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10945163/

10-10 23:40