Start New Discussion within our Web Development Community

Hi ,

I have return type object is "$answer" and I am getting the output by ussing "echo $answer"; is :

  'AnswerId' => int 1
  'Comment' => string 'The license is found.OK'

  'LicenseInt' => 
         'LicenseID' => string 'L005673'.                                                                                                             'Prod_ID' => int 5644
      'LicenseDate' => 
          public 'date' => string '2020-12-12 00:00:00' 
      'LicensesIssued' => int 0
      'VendorStr' => string '

  Now I am able to display the value by 

echo $answer->AnswerId;

but unable to display the value 'LicenseID' in array 'LicenseInt' or 'date' in array 'LicenseDate'.

If the snippet you've posted is for the $answer variable, then it looks to actually be an array, not an object. Do you have the actual var_dump output?

Based on the above:

echo $answer['AnswerId'];
echo $answer['LicenseInt']['licenseID'];
echo $answer['LicenseInt']['Prod_ID'];
echo $answer['LicenseInt']['LicenseDate']->date;

Hi ,

The displayed output using


and from your code giving the error :Fatal error: Cannot use object of type .

if the property "AnswerID" is your array, you can access is like this:


Hi ,
see wich is done and which is not done marked on the right side.

  public 'AnswerId' => int 1                                //done 
  public 'Comment' => string 'The license is found.OK' ()   //done
  public 'LicenseInt' => 
      'LicenseID' => string 'lkjljljljlkjlljljlkjlkjlj'      //done                                                                         ' (length=100)
      'Prod_ID' => int 5652                                 //done
      'LicensesSold' => int 0                               //done
      'Days' => int 0                                       //done
      'LicExpirDate' => 
          public 'date' => string '2001-01-01 00:00:00'     //not done
          public 'timezone_type' => int 3                    //not done
          public 'timezone' => string 'RPC'                 //not done           

respective syntax and output given here

echo $answer->AnswerId;   //working 
echo $answer->Comment;   //working
echo $answer->LicenceInt['LicenceID']; //working
echo $answer->LicenceInt['LicenceSold'];  //working

echo $answer->LicenceInt->LicExpirDate['timezone_type'];   //not working 

because which is working is array in object but which is object in object is not working

The problem is that you're accessing LicenceInt as an object when previously you've accessed it as an array.


didn't display any error but there is no output

   in this 
   already I tried it out
This question has already been answered. Start a new discussion instead.