Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By almamun on
I'm trying to print data from a stdClass object.
Array
(
[1] => stdClass Object
(
[bid] => 1
[weight] => 0
[name] => Staff
[image] => sites/default/files/image/stars.gif
[href] =>
[unhideable] => 0
[fixedweight] => 0
[doesnotcounttolimit] => 0
[userweight] =>
[tid] => 0
[coalescedweight] => 0
[class] => badge Staff
)
)
Not sure how to print some of the labels and values.
----------------------------
Dinajpur- My District Portal,
Rangpur-Another Local Portal (Drupal Powered)
Banglajogot- Bangla Web Design Blog (Drupal Powered)
JoomlaBangla - Joomla! Bangla Support Site
Comments
print $object->name;print
...etc
Without knowing more context thats the basic way to print object data with the properties being string as they are here.
This object is in an array. So if you need to print a property from each object in an array you can do
Not sure how to print some of
If you know the name of the object property, you can output it directly by combining array and object notation like so:
If you're after the labels, you can either use get_object_vars() or simply cast the object to an array - both of which end up with an array with the same structure as your original object.
get_object_vars:
Casting:
Both of which produce:
You can then step through the resulting array and output key/value pairs, or extract the labels using array_keys(), or whatever it is you're wanting to do with it.
++Andy
Developing Drupal websites for Livelink New Media since 2008
Useful
BEst and useful
Use this
use this code
it should be work for you
Happy coding
Cheers