0

Hi ,

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

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

  'LicenseInt' => 
         array
         'LicenseID' => string 'L005673’.                                                                                                             'Prod_ID' => int 5644
      'LicenseDate' => 
        object(DateTime)[35]
          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'.

3
Contributors
10
Replies
13
Views
4 Years
Discussion Span
Last Post by subrata_ushasi
0

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;
0

Hi ,

The displayed output using

var_dump(AnswerId);

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

Edited by subrata_ushasi: word misplaced

0

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

$answer->AnswerId["LicenseInt"]["LicenseID"]
0

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

object($answer)
  public 'AnswerId' => int 1                                //done 
  public 'Comment' => string 'The license is found.OK' ()   //done
  public 'LicenseInt' => 
    array
      'LicenseID' => string 'lkjljljljlkjlljljlkjlkjlj'      //done                                                                         ' (length=100)
      'Prod_ID' => int 5652                                 //done
      'LicensesSold' => int 0                               //done
      'Days' => int 0                                       //done
      'LicExpirDate' => 
        object(DateTime)[34]
          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

but 
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

0

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

$answer->LicenceInt['LicExpirDate']->timezone_type;
0

didn't display any error but there is no output

   in this 
   $answer->LicenceInt['LicExpirDate']->timezone_type;
   already I tried it out
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.