0

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>";       
        } 
    }  
    }       
3
  • Use foreach for iteration or array_walk: array_walk($vehicles, function($vehicle, $key){ echo "{$key}=>{$vehicle['Emission Badge']}"; }); Commented Jul 23, 2014 at 13:23
  • i tried everything but not getting the output as i needed and getting errors. Commented Jul 23, 2014 at 13:24
  • as the answer suggest below i used foreach same way and getting this errors:Warning: Illegal string offset 'Emission Badge' in /www/1/html/webservices/schwackeNet/index.php on line 17 Call Stack # Time Memory Function Location 1 0.0010 134564 {main}( ) ../index.php:0 Commented Jul 23, 2014 at 13:27

1 Answer 1

0

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>';
10
  • Believe me its not that simple..i am getting errors for every parameters now as Warning: Illegal string offset 'Emission Badge' in /www/1/html/webservices/schwackeNet/index.php and i tried foreach also before but still getting errors..i think i have to use 2 foreach loop but dont know how to use it Commented Jul 23, 2014 at 13:23
  • Ah i see, your array is not multidimensional, then is simple. You dont need to iterate over the result, i updated the code. But please you should learn some basics regarding coding. Commented Jul 23, 2014 at 13:27
  • I also added an link to the php documentation for you about arrays. Commented Jul 23, 2014 at 13:29
  • yes definately thank you very much...But still i am getting output as 4, 146, D, Array :( same like before... and without iterating how can i get the all the values from SerialEquipment Parameter ? And without iterating i also cant format my output properly i guess... Commented Jul 23, 2014 at 13:31
  • That are the values of the corresponding array keys. SerialEquipment seems to be also an array which you need to iterate. Commented Jul 23, 2014 at 13:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.