Jump to content

Array Issue


ainoy31

Recommended Posts

Hello-

 

I have an array that is as follows:

Array ( [0] => stdClass Object ( [hostname] => [value] => 66.249.66.165 [hostserial] => 3 ) [1] => stdClass Object ( [hostname] => [value] => 209.135.152.37 [hostserial] => 4 ) )

 

I am having an issue accessing the elements.  I have tried using $array['hostserial'] and $array->hostserial.  I get a notice warning of undefined index value.  I am missing something here.  Much appreciation.  AM

 

Link to comment
https://forums.phpfreaks.com/topic/107798-array-issue/
Share on other sites

I think what you are saying is that you are trying to access an array of values that is stored inside an object, which is stored inside an array of objects.

 

If my assumption is correct then I think you'd want to do something more like this:

<?php
  echo $array[0]->hostname['value'];//should output 66.249.66.165
  echo $array[0]->hostname['hostserial'];//should output 3
?>

But please correct me if I'm wrong :)

Link to comment
https://forums.phpfreaks.com/topic/107798-array-issue/#findComment-552578
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.