XML 파일로 내보내려는 SESSION 변수가 있습니다. 고객 세부 사항은 foreach 루프의 일부가 아니므로 괜찮습니다. 그러나 고객의 주문은 foreach 루프의 일부입니다.PHP 세션 배열 vars to XML
SESSION 변수 $ _SESSION [ 'invoice']은 (는) cart.php에 정의되어 있습니다. $ _SESSION [ 'invoice'] 배열의 각 개별 값을 검색하여 XML에 배치해야합니다.
<title1>comic title1</title1><qty1>10</qty1><price1>$2.50</price1><cost1>$25.00</cost1><title2>comic title2</title2><qty2>5</qty2><price2>$2.00</price2><cost2>$10.00</cost2>
cart.php 코드 :
$_SESSION['invoice'][$comic_id]=$name . " " . $qty . " $" . $price . " $" . $cost;
xml.php 코드 :이 코드 당신 concatinate 문자열로
<?php
if(!isset($_SESSION)) {
session_start();
}
foreach ($_SESSION['invoice'] as $value);
$test_array = array (
$_SESSION['firstname'] => 'firstname',
$_SESSION['lastname'] => 'lastname',
$_SESSION['email'] => 'email',
$_SESSION['addressline1'] => 'addressline1',
$_SESSION['towncity'] => 'towncity',
$_SESSION['postcode'] => 'postcode',
'order' => array (
$_SESSION['total'] => 'total',
$_SESSION['invoice'] => 'order',
),
);
$xml = new SimpleXMLElement('<customer/>');
array_walk_recursive($test_array, array ($xml, 'addChild'));
print $xml->asXML();
이 방법은 모든 연결된 값/행을 배열에서 다시 가져 오지 않으므로 작동하지 않습니다. – Accolade
$ order = json_encode ($ _ SESSION [ 'invoice']); – Accolade