I want to fetch 'video_url' value from the array.I have the array
[field_read_link] => Array (
[und] => Array (
[0] => Array (
[url] => http://localhost/AspireInnerWebsite/
[title] => Read [attributes] => Array ( )
)
)
)
[field_perspective_image] => Array ( )
[field_fb_icon] => Array ( )
[field_twitter_icon] => Array ( )
[field_gplus_icon] => Array ( )
[field_service_line] => Array (
[und] => Array (
[0] => Array (
[tid] => 19
)
)
)
[field_category] => Array (
[und] => Array (
[0] => Array (
[tid] => 31
)
)
)
[field_perspective_menu] => Array (
[und] => Array (
[0] => Array (
[tid] => 44
)
)
)
[field_display_order] => Array (
[und] => Array (
[0] => Array (
[value] => 1
)
)
)
[field_attachment_file] => Array ( )
[field_perspective_video] => Array (
[und] => Array (
[0] => Array (
[video_url] => https://www.youtube.com/embed/vG-5jZpMIHk
[thumbnail_path] => public://video_embed_field_thumbnails/youtube/vG-5jZpMIHk.jpg
[video_data] => a:1:{s:7:"handler";s:7:"youtube";}
[embed_code] =>
[description] => ) ) ) [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] => 1483523222 [last_comment_name] => [last_comment_uid] => 1 [comment_count] => 0 [name] => nivetha [picture] => 0 [data] => a:1:{s:7:"overlay";i:1;} ) ) )`
from that array I want to fetch 'video_url' which is in field_perspective_video
I have tried as
print_r($fields['field_perspective_video'][0]['video_url']);
I caught
Cannot use object of type stdClass as array in line
It means that your $fields
is stdClass (object) instead of array.
If it's from json_decode
, than use json_decode($string, true)
to decode to array instead of object.
Else try using object notation $fields->field_perspective_video[0]->video_url
Its look like stdClass (object) so get like this
$fields->field_perspective_video['und'][0]['video_url'];