2010-08-06 6 views
0

오픈 소스 PHP 래퍼를 편집하여 XML을 내보내려고합니다.XML에서 PHP 로의 배열?

원본 :이처럼 될 수 있도록

$new_invoice = array(
    array(
     "Type"=>"ACCREC", 
     "Contact" => array(
      "ContactID" => "[contact id]" 
     ), 
     "Date" => "2010-04-08", 
     "DueDate" => "2010-04-30", 
     "Status" => "SUBMITTED", 
     "LineAmountTypes" => "Exclusive", 
     "LineItems"=> array(
      "LineItem" => array(
       array(
        "Description" => "Just another test invoice", 
        "Quantity" => "2.0000", 
        "UnitAmount" => "250.00", 
        "AccountCode" => "200" 
       ) 
      ) 
     ) 
    ) 
); 

내가 다른 LineItem을 추가했습니다

$new_invoice = array(
    array(
     "Type"=>"ACCREC", 
     "Contact" => array(
      "ContactID" => "7937FF1D-B135-4BD0-A219-4B621EA3808C" 
     ), 
     "Date" => "2010-04-08", 
     "DueDate" => "2010-04-30", 
     "Status" => "DRAFT", 
     "LineAmountTypes" => "Exclusive", 
     "LineItems"=> array(
      "LineItem" => array(
       array(
        "Description" => "Just another test invoice", 
        "Quantity" => "2.0000", 
        "UnitAmount" => "250.00", 
        "AccountCode" => "200" 
       ) 
      ) 
      "LineItem" => array(
       array(
        "Description" => "Just another test invoice2", 
        "Quantity" => "2.0000", 
        "UnitAmount" => "250.00", 
        "AccountCode" => "200" 
       ) 
      ) 
     ) 
    ) 
); 

을하지만 닫는 브래킷을 기대 "라고 오류가있어) 이 보인다 모든 괄호가 있으므로 혼란 스럽습니다.

답변

1

첫 번째 LineItem 배열 다음에 쉼표가없는 경우

두 개의 배열이 동일한 키 ("LineItem")를 공유하기 때문에 두 번째 배열이 첫 번째 배열을 덮어 쓰지만 구문 오류와 관련이 없습니다.

편집 : 그 문제 (여기 SimpleXML이 같은 것을 사용하고 있다고 가정)을 처리하려면

...

"LineItems"=> array(
    "LineItem" => array(
     array(
      "Description" => "Just another test invoice", 
      "Quantity" => "2.0000", 
      "UnitAmount" => "250.00", 
      "AccountCode" => "200" 
     ), 
     array(
      "Description" => "Just another test invoice2", 
      "Quantity" => "2.0000", 
      "UnitAmount" => "250.00", 
      "AccountCode" => "200" 
     ) 
    ) 
) 
0

당신은 첫 번째 줄의 항목 이후에 쉼표를 ... 잊고 당신의 코드는 다음과 같아야합니다.

<?php 
$new_invoice = array(
    array(
     "Type"=>"ACCREC", 
     "Contact" => array(
      "ContactID" => "7937FF1D-B135-4BD0-A219-4B621EA3808C" 
     ), 
     "Date" => "2010-04-08", 
     "DueDate" => "2010-04-30", 
     "Status" => "DRAFT", 
     "LineAmountTypes" => "Exclusive", 
     "LineItems"=> array(
      "0" => array(
       array(
        "Description" => "Just another test invoice", 
        "Quantity" => "2.0000", 
        "UnitAmount" => "250.00", 
        "AccountCode" => "200" 
       ) 
      ), 
      "1" => array(
       array(
        "Description" => "Just another test invoice2", 
        "Quantity" => "2.0000", 
        "UnitAmount" => "250.00", 
        "AccountCode" => "200" 
       ) 
      ) 
     ) 
    ) 
); 
?> 

또한 두 번째 광고 항목이 첫 번째 광고 항목보다 우선합니다.

나는 그것은 누락 된 쉼표,하지만 다른 사람들이 말했듯이, 두 번째는 첫 번째 덮어 ...

0

카운터를 추천 모든 LINEITEM가 추가 된 후를 증가 할 것이다. 대신이 시도 :

$new_invoice = array(
    array(
     "Type"=>"ACCREC", 
     "Contact" => array(
      "ContactID" => "7937FF1D-B135-4BD0-A219-4B621EA3808C" 
     ), 
     "Date" => "2010-04-08", 
     "DueDate" => "2010-04-30", 
     "Status" => "DRAFT", 
     "LineAmountTypes" => "Exclusive", 
     "LineItems"=> array(
      "LineItem" => array(
       array(
        "Description" => "Just another test invoice", 
        "Quantity" => "2.0000", 
        "UnitAmount" => "250.00", 
        "AccountCode" => "200" 
       ), 
       array(
        "Description" => "Just another test invoice2", 
        "Quantity" => "2.0000", 
        "UnitAmount" => "250.00", 
        "AccountCode" => "200" 
       ) 
      ) 
     ) 
    ) 
); 
print_r($new_invoice); 
0

만 쉼표 (,)가 먼저 "LINEITEM"후 배열에

누락