构建PHP soapClient数组不起作用

时间:2013-09-30 02:54:07

标签: php soap

我有一个成功的soapClient,可以从以下XML示例生成内容

 <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
 <s:Header>
   <ActivityId xmlns="http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics" CorrelationId="f62a50bd-af24-4719-acca-fcfb8770028d">ebc35110-673d-4d15-aacd-020e14a8d62b</ActivityId>
 </s:Header>
 <s:Body>
   <GMDataResponse xmlns="http://xx.com/xx">
   <GMDataResult xmlns:a="http://xx.com/xx/GMData" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
   <a:Users>
     <a:MData.UserData>
       <a:ProjectId>37199</a:ProjectId>
       <a:Name>Hilda Smith</a:Name>
       <a:Number>101</a:Number>
       <a:First>Hilda</a:First>
     </a:MData.UserData>
     <a:MData.UserData>
       <a:ProjectId>37199</a:ProjectId>
       <a:Name>John Smith</a:Name>
       <a:Number>102</a:Number>
       <a:First>John</a:First>
     </a:MData.UserData>

我使用以下内容构建循环并且它可以工作:

 $UsersAr = is_array( $res->GMDataResult->Users )
       ? $res->GMDataResult->Users
       : array( $res->GMDataResult->Users );

 foreach ($UsersAr as $Users) {
     foreach($Users as $UserSet) {
    foreach($UserSet as $u) {
        echo $u->Name ."<br>";
    }
 } 
 }

我试试:

 foreach ($UsersAr as $users) {
$user = $users->MBData.UserData;
echo $user->Name;
 }

它失败了(注意:未定义属性:stdClass :: $ MBData)似乎MBData.UserData中的句点抛出错误?我想要最干净的代码,因为这是一个高容量的过程。

1 个答案:

答案 0 :(得分:1)

$users->{'MBData.UserData'}

$users->MBData.UserData被视为$users->MBDataUserData

的串联

参考:http://www.php.net/manual/en/language.variables.variable.php