重复数组中的元素为PHP肥皂调用

时间:2011-12-15 23:18:54

标签: php 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'
        )
        )));

2 个答案:

答案 0 :(得分:4)

所以在我的朋友(和Passing a PHP array in a SOAP call)的帮助下,我得到了解决方案。主要问题是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'
            ))));

答案 1 :(得分:0)

如果您没有明确地为重复项目编号,会发生什么?

$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'
    )
    )));

我想你应该看看这个类似的问题:PHP repeated elements in a soap call