foreach在PHP中获取数组索引结果

时间:2014-07-22 08:50:44

标签: php arrays soap parameters

我从SOAP客户端获得了以下参数作为响应。但我只希望很少有人能够表现出来。我得到了正确的结果,但它只适用于1辆车,我有超过1辆车。所以我不知道如何循环以获得结果。

1辆车的输出

array (size=5)
  'SchwackeCode' => int 10130969
  'WE_Number' => int 19373134
  'HSN' => string '0005' (length=4)
  'TSN' => string 'AMP' (length=3)
  'VIN' => string '12345678901472583' (length=17)

代码:

$client = new SoapClient($wsdl, $options);
$result = $client->getVehicleValuation($params);    
$return = array(
                                    'SchwackeCode' => $result->vehicle->SchwackeCode,
                                    'WE_Number'    => $result->vehicle->WE_Number,
                                    'HSN'          => $result->vehicle->HSN, 
                                    'TSN'          => $result->vehicle->TSN,
                                    'VIN'          => $result->vehicle->Ident_Number,
                                    'WE_Number'    => $result->vehicle->WE_Number                                       
                            );
return $return;

1 个答案:

答案 0 :(得分:0)

好的,那就试试这个简单的代码,

$cnt=0; 
$arr=Array('SchwackeCode','WE_Number','HSN','TSN' );

    foreach($result->Vehicle[$cnt]->Customer[0] as $key=>$val)
   {
         if(in_array($key,$arr)
        {
                    your_piece of code;
         }
          $cnt++;

   }

Didnt测试了这段代码,但希望它能运行。 :)

相关问题