简体   繁体   中英

Repeating elements in an array for a php soap call

I'm making a soap call, but one of the nested elements repeats so it gets overwritten when I create the array, numbering the elements breaks to soap request.

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

So with a bit of help from my friends (and Passing a PHP array in a SOAP call ) I got the solution. The primary problem was that php was overwriting the attendee variable with the second occurrence. I had to find a way to get both elements of attendee stored. Thought I would post here for posterity as it was slightly different than other problems.

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

What happens if you don't explicitely number repeated items, like that ?

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

I guess you should have a look at this similar question : PHP repeated elements in a soap call

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM