在 PHP Soap 调用中重复数组中的元素

发布于 2024-12-21 09:15:12 字数 1769 浏览 1 评论 0原文

我正在进行肥皂调用,但其中一个嵌套元素会重复,因此当我创建数组时,它会被覆盖,对肥皂请求的元素进行编号。

 $result = $client->SaveEventRegistration(array(

    'SetEventRegistrationRQ' => array(

        'Attendees' => array( 
            'Attendee' => array(
                'EventRegistrationTypeID' => '3125',
                'NoofSeats' => '2',
                'RegistrationCost' => '20',
                'Contact' => array(
                    'FirstName' => 'Danny',
                    'LastName' => 'Hulk',
                    'Email' => '[email protected]',
                    'IsForNewsletter' => 'true'
                    )
                ),
                'Attendee' => array(
                'EventRegistrationTypeID' => '3149',
                'NoofSeats' => '2',
                'RegistrationCost' => '30',
                'Contact' => array(
                    'FirstName' => 'Penny',
                    'LastName' => 'Hulk',
                    'Email' => '[email protected]',
                    'IsForNewsletter' => 'true'
                    )
                )
            ),
        'EventId' => '2652',
        'RegistrationBy' => array(
            'FirstName' => 'Incredible',
            'LastName' => 'Hulk',
            'Email' => '[email protected]',
            'EventScheduleId' => '2617'
        )
        )));

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' => '[email protected]',
                    'IsForNewsletter' => 'true'
                    )
                ),
                'Attendee' => array(
                'EventRegistrationTypeID' => '3149',
                'NoofSeats' => '2',
                'RegistrationCost' => '30',
                'Contact' => array(
                    'FirstName' => 'Penny',
                    'LastName' => 'Hulk',
                    'Email' => '[email protected]',
                    'IsForNewsletter' => 'true'
                    )
                )
            ),
        'EventId' => '2652',
        'RegistrationBy' => array(
            'FirstName' => 'Incredible',
            'LastName' => 'Hulk',
            'Email' => '[email protected]',
            'EventScheduleId' => '2617'
        )
        )));

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

妞丶爷亲个 2024-12-28 09:15:12

因此,在我的朋友的帮助下(以及 将 PHP 数组传递给SOAP 调用)我得到了解决方案。主要问题是 php 在第二次出现时覆盖了 attendee 变量。我必须找到一种方法来存储与会者的两个元素。我想我会在这里为后代发帖,因为它与其他问题略有不同。

    // 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' => '[email protected]',
                        'IsForNewsletter' => 'true'
                        ));
$attendee[] = array(
                    'EventRegistrationTypeID' => '3149',
                    'NoofSeats' => '2',
                    'RegistrationCost' => '20',
                    'Contact' => array(
                        'FirstName' => 'Penny',
                        'LastName' => 'Hulk',
                        'Email' => '[email protected]',
                        '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' => '[email protected]',
                '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' => '[email protected]',
                        'IsForNewsletter' => 'true'
                        ));
$attendee[] = array(
                    'EventRegistrationTypeID' => '3149',
                    'NoofSeats' => '2',
                    'RegistrationCost' => '20',
                    'Contact' => array(
                        'FirstName' => 'Penny',
                        'LastName' => 'Hulk',
                        'Email' => '[email protected]',
                        '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' => '[email protected]',
                'EventScheduleId' => '2617'
            ))));
送舟行 2024-12-28 09:15:12

如果您不明确地对重复的项目进行编号,会发生什么情况?

$result = $client->SaveEventRegistration(array(

'SetEventRegistrationRQ' => array(

    'Attendees' => array( 

        array(
            'EventRegistrationTypeID' => '3125',
            'NoofSeats' => '2',
            'RegistrationCost' => '20',
            'Contact' => array(
                'FirstName' => 'Danny',
                'LastName' => 'Hulk',
                'Email' => '[email protected]',
                'IsForNewsletter' => 'true'
                )
            ),
        array(
            'EventRegistrationTypeID' => '3149',
            'NoofSeats' => '2',
            'RegistrationCost' => '30',
            'Contact' => array(
                'FirstName' => 'Penny',
                'LastName' => 'Hulk',
                'Email' => '[email protected]',
                'IsForNewsletter' => 'true'
                )
            )
        ),
    'EventId' => '2652',
    'RegistrationBy' => array(
        'FirstName' => 'Incredible',
        'LastName' => 'Hulk',
        'Email' => '[email protected]',
        'EventScheduleId' => '2617'
    )
    )));

我想你应该看看这个类似的问题:PHP在肥皂中重复元素致电

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' => '[email protected]',
                'IsForNewsletter' => 'true'
                )
            ),
        array(
            'EventRegistrationTypeID' => '3149',
            'NoofSeats' => '2',
            'RegistrationCost' => '30',
            'Contact' => array(
                'FirstName' => 'Penny',
                'LastName' => 'Hulk',
                'Email' => '[email protected]',
                'IsForNewsletter' => 'true'
                )
            )
        ),
    'EventId' => '2652',
    'RegistrationBy' => array(
        'FirstName' => 'Incredible',
        'LastName' => 'Hulk',
        'Email' => '[email protected]',
        'EventScheduleId' => '2617'
    )
    )));

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文