user4407686
user4407686

Reputation:

How to get the array elements of a specific key from an associative array in following scenario?

I've on associative array titled $group_list. When I print it using print_r($grouop_list) it prints following content:

Pages_Component_Controller_List Object
(
    [data] => Array
        (
            [0] => Array
                (
                    [vanity_url] => 
                    [page_type] => 1
                    [category_name] => Athletic
                    [profile_server_id] => 0
                    [profile_user_image] => 
                    [is_liked] => 592
                    [page_id] => 174
                    [app_id] => 0
                    [view_id] => 0
                    [type_id] => 7
                    [category_id] => 170
                    [user_id] => 244
                    [title] => Olympic Games
                    [code] => 
                    [unv_title] => 1398
                    [campus_name] => Mississippi State University, Meridian
                    [group_type] => close
                    [reg_method] => 0
                    [landing_page] => wall
                    [time_stamp] => 1423362356
                    [image_path] => 
                    [image_server_id] => 0
                    [total_like] => 1
                    [total_dislike] => 0
                    [total_comment] => 0
                    [privacy] => 0
                    [designer_style_id] => 0
                    [cover_photo_id] => 
                    [cover_photo_position] => 
                    [location_latitude] => 
                    [location_longitude] => 
                    [location_name] => 
                    [use_timeline] => 0
                    [classroom] => 
                    [time_class] => 
                    [num_weeks] => 
                    [country_iso] => MS
                    [term] => 
                    [year] => 2015
                    [profile_page_id] => 0
                    [user_server_id] => 0
                    [user_name] => profile-244
                    [full_name] => Campusknot .
                    [gender] => 0
                    [user_image] => 2015/02/ade52764529ccd469bbddf98aa62712c%s.jpg
                    [is_invisible] => 0
                    [user_group_id] => 7
                    [language_id] => 
                    [link] => http://54.174.50.242/group/174/
                    [aFeed] => Array
                        (
                            [feed_display] => mini
                            [comment_type_id] => pages
                            [privacy] => 0
                            [comment_privacy] => 0
                            [like_type_id] => pages
                            [feed_is_liked] => 592
                            [feed_is_friend] => 
                            [item_id] => 174
                            [user_id] => 244
                            [total_comment] => 0
                            [feed_total_like] => 1
                            [total_like] => 1
                            [feed_link] => http://54.174.50.242/group/174/
                            [feed_title] => Olympic Games
                            [type_id] => pages
                        )

                )

            [1] => Array
                (
                    [vanity_url] => 
                    [page_type] => 1
                    [category_name] => Academic
                    [profile_server_id] => 0
                    [profile_user_image] => 
                    [is_liked] => 
                    [page_id] => 170
                    [app_id] => 0
                    [view_id] => 0
                    [type_id] => 7
                    [category_id] => 169
                    [user_id] => 244
                    [title] => Master of Engineering
                    [code] => ME
                    [unv_title] => 1398
                    [campus_name] => 
                    [group_type] => close
                    [reg_method] => 0
                    [landing_page] => wall
                    [time_stamp] => 1421152531
                    [image_path] => 
                    [image_server_id] => 0
                    [total_like] => 0
                    [total_dislike] => 0
                    [total_comment] => 0
                    [privacy] => 0
                    [designer_style_id] => 0
                    [cover_photo_id] => 
                    [cover_photo_position] => 
                    [location_latitude] => 
                    [location_longitude] => 
                    [location_name] => 
                    [use_timeline] => 0
                    [classroom] => traditional
                    [time_class] => 01:10 AM-04:00 AM
                    [num_weeks] => Mon-Sat
                    [country_iso] => MS
                    [term] => fall
                    [year] => 2015
                    [profile_page_id] => 0
                    [user_server_id] => 0
                    [user_name] => profile-244
                    [full_name] => Campusknot .
                    [gender] => 0
                    [user_image] => 2015/02/ade52764529ccd469bbddf98aa62712c%s.jpg
                    [is_invisible] => 0
                    [user_group_id] => 7
                    [language_id] => 
                    [link] => http://54.174.50.242/group/170/
                    [aFeed] => Array
                        (
                            [feed_display] => mini
                            [comment_type_id] => pages
                            [privacy] => 0
                            [comment_privacy] => 0
                            [like_type_id] => pages
                            [feed_is_liked] => 
                            [feed_is_friend] => 
                            [item_id] => 170
                            [user_id] => 244
                            [total_comment] => 0
                            [feed_total_like] => 0
                            [total_like] => 0
                            [feed_link] => http://54.174.50.242/group/170/
                            [feed_title] => Master of Engineering
                            [type_id] => pages
                        )


                )
)
    [_sModule:Phpfox_Component:private] => pages
    [_sComponent:Phpfox_Component:private] => controller/list
    [_sCacheVar:Phpfox_Component:private] => 
)

Actually I want all the array elements from belonging to data key only. How should I get this data?

Please help me.

Thanks.

Upvotes: 0

Views: 31

Answers (2)

Tanmoy Roy
Tanmoy Roy

Reputation: 1

Try it:

echo $grouop_list['data'][0]->title;

echo $grouop_list['data'][0]->time_stamp;

Upvotes: 0

silkfire
silkfire

Reputation: 25935

Your $group_list is most probably not an array but indeed an object.

To access the data array you simply use the arrow operator (->):

$data = $group_list->data;

Upvotes: 1

Related Questions