1,105,232 Community Members

display array value in object

Member Avatar
subrata_ushasi
Junior Poster
115 posts since Aug 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 6 [?]
Skill Endorsements: 0 [?]
 
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'.

Member Avatar
blocblue
Practically a Posting Shark
828 posts since Jan 2008
Reputation Points: 238 [?]
Q&As Helped to Solve: 162 [?]
Skill Endorsements: 16 [?]
Featured
 
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;
Member Avatar
subrata_ushasi
Junior Poster
115 posts since Aug 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 6 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi ,

The displayed output using

var_dump(AnswerId);

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

Member Avatar
blocblue
Practically a Posting Shark
828 posts since Jan 2008
Reputation Points: 238 [?]
Q&As Helped to Solve: 162 [?]
Skill Endorsements: 16 [?]
Featured
 
0
 

Please post the output from var_dump($answer) or whatever your variable is called.

Member Avatar
subrata_ushasi
Junior Poster
115 posts since Aug 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 6 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi ,
done this issue.
Solution is :

echo $answer->LicenseInt['LicensesSold']; 
Question Answered as of 1 Year Ago by blocblue
Member Avatar
gon1387
Posting Whiz in Training
242 posts since Jan 2011
Reputation Points: 22 [?]
Q&As Helped to Solve: 38 [?]
Skill Endorsements: 4 [?]
 
0
 

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

$answer->AnswerId["LicenseInt"]["LicenseID"]
Member Avatar
subrata_ushasi
Junior Poster
115 posts since Aug 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 6 [?]
Skill Endorsements: 0 [?]
 
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

Member Avatar
blocblue
Practically a Posting Shark
828 posts since Jan 2008
Reputation Points: 238 [?]
Q&As Helped to Solve: 162 [?]
Skill Endorsements: 16 [?]
Featured
 
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;
Member Avatar
subrata_ushasi
Junior Poster
115 posts since Aug 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 6 [?]
Skill Endorsements: 0 [?]
 
0
 

didn't display any error but there is no output

   in this 
   $answer->LicenceInt['LicExpirDate']->timezone_type;
   already I tried it out
Member Avatar
blocblue
Practically a Posting Shark
828 posts since Jan 2008
Reputation Points: 238 [?]
Q&As Helped to Solve: 162 [?]
Skill Endorsements: 16 [?]
Featured
 
0
 

Did you echo the response? Have you tried to var_dump the response?

Member Avatar
subrata_ushasi
Junior Poster
115 posts since Aug 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 6 [?]
Skill Endorsements: 0 [?]
 
0
 

Yes I tried echo and tried var_dump but no output as yet

You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: