0

I am trying to access data inside a php object. I am confused about what the exact stynax is. Here is the output of the object:

stdClass Object ( [vid] => 10 [uid] => 1 [title] => Beachhead Don [log] => [status] => 1 [comment] => 1 [promote] => 0 [sticky] => 0 [ds_switch] => [nid] => 10 [type] => product [language] => und [created] => 1357668665 [changed] => 1358198386 [tnid] => 0 [translate] => 0 [revision_timestamp] => 1358198386 [revision_uid] => 1 [model] => B 3000 [list_price] => 0.00000 [cost] => 0.00000 [sell_price] => 1.00000 [weight] => 0 [weight_units] => lb [length] => 0 [width] => 0 [height] => 0 [length_units] => in [pkg_qty] => 1 [default_qty] => 1 [unique_hash] => 2eec0fcc8483f3a3541870fb24223296 [ordering] => 0 [shippable] => 0 [price] => 1.00000 [body] => Array ( [und] => Array ( [0] => Array ( [value] => Description info ))))))))))))))))))))))))))))))))))))))0 [summary] => [format] => filtered_html [safe_value] =>Description info ))))))))))))))))))))))))))))))))))))))0[safe_summary] => ) ) ) [uc_product_image] => Array ( [und] => Array ( [0] => Array ( [fid] => 11 [alt] => [title] => [width] => 90 [height] => 120 [uid] => 1 [filename] => beachhead_don.jpg [uri] => public://beachhead_don.jpg [filemime] => image/jpeg [filesize] => 14342 [status] => 1 [timestamp] => 1357668665 [rdf_mapping] => Array ( ) ) ) ) [field_author] => Array ( [und] => Array ( [0] => Array ( [value] => John B. Romesier [format] => [safe_value] => John B. Romesier ) ) ) [field_publisher] => Array ( [und] => Array ( [0] => Array ( [value] => Unknown [format] => [safe_value] => Unknown ) ) ) [field_release_date] => Array ( [und] => Array ( [0] => Array ( [value] => Mar 2012 [format] => [safe_value] => Mar 2012 ) ) ) [field_number_of_pages] => Array ( [und] => Array ( [0] => Array ( [value] => 123 ) ) ) [field_catagory] => Array ( [und] => Array ( [0] => Array ( [tid] => 4 ) ) ) [field_book_type] => Array ( [und] => Array ( [0] => Array ( [tid] => 1 ) ) ) [field_isbn] => Array ( ) [field_about_the_author] => Array ( [und] => Array ( [0] => Array ( [value] => Beachhed Don authoer............................ [format] => [safe_value] => Beachhed Don authoer............................ ) ) ) [rdf_mapping] => Array ( [rdftype] => Array ( [0] => sioc:Item [1] => foaf:Document ) [title] => Array ( [predicates] => Array ( [0] => dc:title ) ) [created] => Array ( [predicates] => Array ( [0] => dc:date [1] => dc:created ) [datatype] => xsd:dateTime [callback] => date_iso8601 ) [changed] => Array ( [predicates] => Array ( [0] => dc:modified ) [datatype] => xsd:dateTime [callback] => date_iso8601 ) [body] => Array ( [predicates] => Array ( [0] => content:encoded ) ) [uid] => Array ( [predicates] => Array ( [0] => sioc:has_creator ) [type] => rel ) [name] => Array ( [predicates] => Array ( [0] => foaf:name ) ) [comment_count] => Array ( [predicates] => Array ( [0] => sioc:num_replies ) [datatype] => xsd:integer ) [last_activity] => Array ( [predicates] => Array ( [0] => sioc:last_activity_date ) [datatype] => xsd:dateTime [callback] => date_iso8601 ) ) [cid] => 0 [last_comment_timestamp] => 1357668665 [last_comment_name] => [last_comment_uid] => 1 [comment_count] => 0 [name] => admin [picture] => 0 [data] => b:0; [entity_view_prepared] => 1 ) 

I am trying to retrive the [value] of Description info ))))))))))))))))))))))))))))))))))))))0

I tried this

<?php $node = menu_get_object(); //drupal code if ( !empty($node) ) { print $node ->body=>und=>0=>value; }?> 

and got an error about the '=' sign. What is the proper way to get my data?

2
  • format your code in proper manner so that we may have easy look on it , rather then long scrolling Commented Jan 15, 2013 at 18:41
  • I formatted it enough so that you can see the elements I need. Commented Jan 15, 2013 at 18:44

2 Answers 2

2

[body] and [und] are arrays, so access them like this:

echo $node->body['und'][0]['value']; 
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks! But when is the => used then? I thought that -> was for objects and => for arrays.
=> is for arrays, but when you are setting values in array, for example $t = array('key' => 'value');.
0

It should be: $node->body['und'][0]['value']

'Body' and 'und' are Arrays and need to be accessed with array syntax([]).

Accessing these values directly is sometimes frowned upon in drupal. You may want to look into: http://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_render/7

1 Comment

I'm a bit new to Drupal 7. I have noticed render(); being used in the node.tpl.php file, but I'm not so clear about how to use it, and the Drupal documentation isn't so clear to me. What would the drupal command be here to get my data?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.