繁体   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