简体   繁体   中英

array using foreach loop statement in php not displaying results

I got the following parameters as a response from SOAP client in which all the parameters have single values which is displaying properly and only the SerialEquipment parameter is an array and have many values and not able to display the result of this parameter. It just echoing as an Array.I am trying since long time but unable to display the result for SerialEquipment.

array result using var_dump:

   array (size=4)
  'Emission Badge' => int 4
  'Car Tax' => float 146
  'Tax Type' => string 'D' (length=1)
  'SerialEquipment' => 
    array (size=41)
      0 => 
        object(stdClass)[6]
          public 'Code' => int 204093
          public 'Desc_Short' => string 'Ablagefach mittig in Gepäckraumtrennwand;ESACO_UG(122)' (length=55)
          public 'Desc_Long' => string 'Ablagefach mittig in Gepäckraumtrennwand inkl. verschiebbarem Haltenetz' (length=72)

      1 => 
        object(stdClass)[8]
          public 'Code' => int 160452
          public 'Desc_Short' => string 'Airbag für Fahrer und Beifahrer, 2-stufi;ESACO_UG(103)' (length=55)
          public 'Desc_Long' => string 'Airbag für Fahrer und Beifahrer 2-stufig' (length=41)

Code:

function getVehicleValuation()
{   
    $result = $client->getVehicleValuation($params);    
    $return = array(
    'Emission Badge'    => $result->vehicle->Emission_Badge,
    'Car Tax'   => $result->vehicle->Car_Tax,
    'Tax Type'  => $result->vehicle->Tax_Type,
    'SerialEquipment' => $result->vehicle->SerialEquipment
);
return $return; 
}

Display result here:

 if($parameter['aktion'] == 'getVehicle') 
    {       
        $returned_array=getVehicleValuation();
        foreach($returned_array as $objects) 
    {
        foreach($objects as $key => $obj) 
        {       
        echo "key.: " . $key . "<br>";
        echo $obj->Code . "<br>";
        echo $obj->Desc_Short . "<br>";
        echo $obj->Desc_Long . "<br>";       
        } 
    }  
    }       

Check the php documentation regarding arrays and how to use them.

$vehicle = getVehicleValuation();
echo $vehicle['Emission Badge'] . ', ' . $vehicle['Car Tax'] . ', ' . $vehicle['Tax Type'] . ', ' . $vehicle['SerialEquipment'] . '<\ br>';

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