如何在以下场景中从关联数组中获取特定键的数组元素?

时间:2015-02-11 07:17:02

标签: php arrays multidimensional-array associative-array key-value

我使用名为$group_list的关联数组。当我使用print_r($grouop_list)打印它时,它打印以下内容:

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] => 
)

实际上我希望所有数组元素都只属于数据键。我该如何获得这些数据?

请帮帮我。

感谢。

2 个答案:

答案 0 :(得分:1)

你的$group_list很可能不是一个数组,但确实是一个对象。

要访问数据阵列,只需使用箭头操作符(->):

$data = $group_list->data;

答案 1 :(得分:0)

试一试:

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

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