动态添加项目到数组Mike42 PHP

时间:2018-07-02 14:10:11

标签: php arrays thermal-printer

实际上,我使用的是escpos-php热敏打印机mike42库,要在发票上添加项目,这里有一个数组,那么如何动态添加它们?

有数组:

$items = array(
    new item("Example item #1", "4.00"),
    new item("Another thing", "3.50"),
    new item("Something else", "1.00"),
    new item("A final item", "4.45"),
);

我想要类似的东西

$items = array(
while($fetch = mysqli__fetch_assoc($sql)){
        new item($fetch['item'], $fetch['price']),
}
);

1 个答案:

答案 0 :(得分:2)

您快到了,只需从数组中取出while循环即可。

$items = []; // Or array()

while($fetch = mysqli__fetch_assoc($sql)){
    $items[] = new item($fetch['item'], $fetch['price']);
}