簡體   English   中英

重復數組中的元素以進行PHP Soap調用

[英]Repeating elements in an array for a php soap call

我正在進行soap調用,但是嵌套元素之一重復出現,因此在創建數組時對它進行覆蓋,對元素編號進行編號以使其符合soap請求。

 $result = $client->SaveEventRegistration(array(

    'SetEventRegistrationRQ' => array(

        'Attendees' => array( 
            'Attendee' => array(
                'EventRegistrationTypeID' => '3125',
                'NoofSeats' => '2',
                'RegistrationCost' => '20',
                'Contact' => array(
                    'FirstName' => 'Danny',
                    'LastName' => 'Hulk',
                    'Email' => 'hulk@domain.co.nz',
                    'IsForNewsletter' => 'true'
                    )
                ),
                'Attendee' => array(
                'EventRegistrationTypeID' => '3149',
                'NoofSeats' => '2',
                'RegistrationCost' => '30',
                'Contact' => array(
                    'FirstName' => 'Penny',
                    'LastName' => 'Hulk',
                    'Email' => 'hulk@domain.co.nz',
                    'IsForNewsletter' => 'true'
                    )
                )
            ),
        'EventId' => '2652',
        'RegistrationBy' => array(
            'FirstName' => 'Incredible',
            'LastName' => 'Hulk',
            'Email' => 'hulk@domain.co.nz',
            'EventScheduleId' => '2617'
        )
        )));

因此,在朋友的幫助下(並在SOAP調用中傳遞了PHP數組 ),我得到了解決方案。 主要問題是php在第二次出現時覆蓋了與會者變量。 我必須找到一種方法來存儲與會者的兩個要素。 我以為我會在這里發表后代,因為它與其他問題略有不同。

    // turn $attendee into an array (I think it's non-associative?)
      $attendee = array();
   // create the elements that repeat. Note the name of the array becomes part of the soap call so must be the right parameter you intend to send in the SOAP call.
      $attendee[] = array(
                    'EventRegistrationTypeID' => '3125',
                    'NoofSeats' => '2',
                    'RegistrationCost' => '20',
                    'Contact' => array(
                        'FirstName' => 'Danny',
                        'LastName' => 'Hulk',
                        'Email' => 'Danny@domain.co.nz',
                        'IsForNewsletter' => 'true'
                        ));
$attendee[] = array(
                    'EventRegistrationTypeID' => '3149',
                    'NoofSeats' => '2',
                    'RegistrationCost' => '20',
                    'Contact' => array(
                        'FirstName' => 'Penny',
                        'LastName' => 'Hulk',
                        'Email' => 'Penny@domain.co.nz',
                        'IsForNewsletter' => 'true'
                        ));


 // make the SOAP call ($client defined elsewhere). Insert the array created above in the appropriate place inside the correct tag (Attendees in my case).  

$result = $client->SaveEventRegistration(array(

        'SetEventRegistrationRQ' => array(

            'Attendees' => $attendee,
            'EventId' => '2652',
            'RegistrationBy' => array(
                'FirstName' => 'Incredible',
                'LastName' => 'Hulk',
                'Email' => 'hulk@domain.co.nz',
                'EventScheduleId' => '2617'
            ))));

如果您不明確地對重復的項目編號,會發生什么?

$result = $client->SaveEventRegistration(array(

'SetEventRegistrationRQ' => array(

    'Attendees' => array( 

        array(
            'EventRegistrationTypeID' => '3125',
            'NoofSeats' => '2',
            'RegistrationCost' => '20',
            'Contact' => array(
                'FirstName' => 'Danny',
                'LastName' => 'Hulk',
                'Email' => 'hulk@domain.co.nz',
                'IsForNewsletter' => 'true'
                )
            ),
        array(
            'EventRegistrationTypeID' => '3149',
            'NoofSeats' => '2',
            'RegistrationCost' => '30',
            'Contact' => array(
                'FirstName' => 'Penny',
                'LastName' => 'Hulk',
                'Email' => 'hulk@domain.co.nz',
                'IsForNewsletter' => 'true'
                )
            )
        ),
    'EventId' => '2652',
    'RegistrationBy' => array(
        'FirstName' => 'Incredible',
        'LastName' => 'Hulk',
        'Email' => 'hulk@domain.co.nz',
        'EventScheduleId' => '2617'
    )
    )));

我想您應該看看這個類似的問題: 在soap調用中PHP重復了元素

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM