dongqiangou5724 2018-12-03 05:11
浏览 36

如何获取foreach之外的所有xml数据或如何在xml中声明此foreach

   foreach($items as $item => $values) {
   $_product =  wc_get_product( $values['data']->get_id()); 
    $quantity = $values['quantity'];
        $length =  $_product->get_length(); 
    $width  =  $_product->get_width();  
        $height =  $_product->get_height();     

    if(($_product->get_weight()) && ($values['quantity'])){
           $weight = $_product->get_weight() *  $values['quantity'];
    }else{
        $weight = $_product->get_weight();
     } 

 $test_array = array (
'PackageType' => 'ITEM',
'Items' => $quantity,
'TotalKgs' => $weight,
'TotalCubic' => '0',
'Length' => $length,
'Width' => $width,
'Height' => $height,    
);

$xml_data1 = array_to_xml($test_array, new SimpleXMLElement('<LineItem/>'));
$dom = dom_import_simplexml($xml_data1);
$xml_data = $dom->ownerDocument->saveXML($dom->ownerDocument->documentElement);
//print_r( $xml_data);
$testing = htmlentities($xml_data);
$testing1 =html_entity_decode($testing);
echo    $testing1;
 }

I need all the xml datas from $testing1 out side the foreach in the variable to pass on the xml I need all the xml datas from $testing1 out side the foreach in the variable to pass on the xml

  • 写回答

1条回答 默认 最新

  • douchuoxuan3177 2018-12-03 05:29
    关注

    Why don't you declare Global Variables such as $globalXML = ""; and then, inside the foreach loop, simply run at the end $globalXML .= $testing1;?

    In this way, it'll keep adding the parsed XML one by one to the Global Variable until the foreach is finished running.

    Besides, you'll be able to use the $globalXML variable anywhere within the document!

    Hope that helps!!

    评论

报告相同问题?

悬赏问题

  • ¥30 vmware exsi重置后登不上
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?
  • ¥15 电磁场的matlab仿真
  • ¥15 mars2d在vue3中的引入问题
  • ¥50 h5唤醒支付宝并跳转至向小荷包转账界面