如何使用 php 创建重复的 xml $writer 元素

处理订单 xml 以直接运送给供应商,他们希望将产品添加到一定数量的数量,因此不


xmlwriter 的部分是在按下订单按钮并且管理员收到管理员警报时


但我真的看不到或找不到可以做到这一点的代码


foreach ($order_products as $order_product) {


$writer->startElement("products");


$writer->writeElement('art', $order_product['model']);

$writer->writeElement('quantity',$order_product['quantity']);

// what i thought of was 


$order_product['quantity'] * $writer->writeElement('art', $order_product['model']);  ;

// something like that really dont know where to start with this one


$writer->endElement();


}


what the suplier wants is if quantity is 3


<product>1234</product><product>1234</product><product>1234</product>


子衿沉夜
浏览 153回答 1
1回答

扬帆大鱼

如果需要<art>多次添加基于quantity,只需创建一个 for 循环:for ( $i = 0; $i < $order_product['quantity']; $i++ ){&nbsp; $writer->writeElement( 'art', $order_product['model'] );}https://www.php.net/manual/en/control-structures.for.php
打开App,查看更多内容
随时随地看视频慕课网APP