0

I am getting the result from the SOAP client as an response. I just have to analyze the structure of the parameter and display the results accordingly. I have the following srucutre for SerialEquipment and i am getting the results peoperly for all the parameters except the Esaco parameter. The Esaco parameter is an array object and it resides inside the SerialEquipment array. I am trying to fetch the response from Esaco array object but getting an error as Invalid arguments supplied for foreach. I am not understanding how to get the results for Esaco Parameter by looping properly.Just a small mistake i am doing in looping the array.

Code:

foreach($Serial as $key => $obj)
   {
        echo "<b>"."Serial Equipment=>" . $key . "</b>"."<br>";
        echo "Code=>". $obj->Code . "<br>";
        echo "Desc Short=>". $obj->Desc_Short . "<br>";
        echo "Desc Long=>". $obj->Desc_Long . "<br>";


        foreach($obj->Esaco as $key2 => $obj2)  
        {  
            if($obj2 === null){
        // doesn't contain Esaco
        break;
            }
            else{
              echo "<b>"."Esaco=>" . $key2 . "</b>"."<br>";                 
            echo "EsacoMainGroupCode=>". $obj2->EsacoMainGroupCode . "<br>";
            echo "EsacoMainGroupDesc=>". $obj2->EsacoMainGroupDesc . "<br>";
            echo "EsacoSubGroupCode=>".  $obj2->EsacoSubGroupCode . "<br>";
            echo "EsacoSubGroupCode=>".  $obj2->EsacoSubGroupDesc . "<br>";
            echo "EsacoSubGroupCode=>".  $obj2->EsacoGroupCode . "<br>";
            echo "EsacoSubGroupCode=>".  $obj2->EsacoGroupDesc . "<br>";  
        }       
        }           
     }      

if($parameter['aktion'] == 'getVehicle') 
{   
     $vehicle = getVehicleValuation();
     $Serial=$vehicle['SerialEquipment'];        
     $VehicleFuel=$vehicle['VehicleFuel'];

        foreach($VehicleFuel as $key => $obj2)
        {           
            echo "Fuel Type=>". $obj2->Fuel_Type . "<br>";
            echo "Fuel Type Code=>". $obj2->Fuel_Type_Code . "<br>";
            echo "ECE_Unit=>". $obj2->ECE_Unit . "<br>"; 
            echo "ECE_In=>". $obj2->ECE_In . "<br>";     
            echo "ECE_Out=>". $obj2->ECE_Out . "<br>";
            echo "ECE_All=>". $obj2->ECE_All . "<br>";
            echo "ECE_CO2=>". $obj2->ECE_CO2 . "<br>";                       
        }   
}

This is my structure for SerialEquipment: enter image description here

2
  • Show var_dump for $vehicle variable Commented Jul 24, 2014 at 7:35
  • please check the updated question for var_dump for SerialEquipment Commented Jul 24, 2014 at 7:38

2 Answers 2

1
if($parameter['aktion'] == 'getVehicle') 
{
    $vehicle = getVehicleValuation();
    if(($serials = $vehicle['SerialEquipment']) === null){
        // doesn't contain SerialEquipment
        break;
    }

    foreach($serials as $serial){
        print "Code =>" . $serial->Code . "<br>";
        print "Desc Short =>" . $serial->Desc_Short . "<br>";

        //...

        foreach($serial->Esaco as $esaco){
            print "EsacoMainGroupCode =>" . $esaco->EsacoMainGroupCode. "<br>";
            print "EsacoMainGroupDesc =>" . $esaco->EsacoMainGroupDesc. "<br>";

            //...
        }
    }
}  

And for the VehicleFuel:

if($parameter['aktion'] == 'getVehicle') 
{   
 $vehicle = getVehicleValuation();
 $Serial=$vehicle['SerialEquipment'];        
 $VehicleFuel=$vehicle['VehicleFuel'];

 $fuelType = $VehicleFuel->Fuel_Type;

 // if there is only going to be one VehicleFuel object Vehicle, then just do..
 echo "Fuel Type =>". fuelType->Fuel_Type . "<br>";
 echo "Fuel Type Code =>". $fuelType->Fuel_Type_Code . "<br>";

 // if there will be more than one, you will want to use a loop...

    foreach($fuelType as $obj)
    {           
        echo "Fuel Type=>". $obj->Fuel_Type . "<br>";
        echo "Fuel Type Code=>". $obj->Fuel_Type_Code . "<br>";
        echo "ECE_Unit=>". $obj->ECE_Unit . "<br>"; 
        echo "ECE_In=>". $obj->ECE_In . "<br>";     
        echo "ECE_Out=>". $obj->ECE_Out . "<br>";
        echo "ECE_All=>". $obj->ECE_All . "<br>";
        echo "ECE_CO2=>". $obj->ECE_CO2 . "<br>";                       
    }   
} 
Sign up to request clarification or add additional context in comments.

14 Comments

hello Alex it will not work because u have to loop inside loop in order to get all the values for Esaco...
Why do you? It's just an object inside an object? There are not more than one Esaco objects in the vehicle object, so there is no need to loop?
@user3844830 I have updated to better reflect your specific example
yes there are multiple values stored inside Esaco object so if we dont loop it, it will only show the first values for Esaco object...
@user3844830 Ah I see, there ARE potentially more than one Esaco object per SerialEquipment object. I have updated my answer.
|
1

The key Esaco is an object not an array. You should change your second foreach.

foreach($Serial as $key => $obj) {       
    echo "Serial Equipment=>" . $key . "<br>";
    echo "Code=>". $obj->Code . "<br>";
    echo "Desc Short=>". $obj->Desc_Short . "<br>";
    echo "Desc Long=>". $obj->Desc_Long . "<br>";  
    foreach($obj->Esaco as $key2 => $obj2) {
        echo $obj2;
        //...
    }           
}    

4 Comments

thanks man its running now :) but i am getting as error in this loopforeach($obj->Esaco as $objects) saying invalig arguments supplied ?
After your edition. You can delete the thrid foreach.
No man when i removed third foreach its giving null values for Esaco :( Actually its showing the values only for those SerialEquipment those have only single time Esaco value. When there are multiple times Esaco values are coming its showing null there
I don't know what you are waiting for in Esaco object but I guess you can do it by yourself. It's the same behavior just loop on this object.

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.