dpdt79577 2015-07-24 09:22
浏览 34
已采纳

如何在php中访问给定数组结构的数组键值?

I have an array which is coming using print_r($variable) in php. I want to modify this array to come in some another form. How can I achieve this.

Array
(
    [body] => Array
        (
            [label] => Body
            [widget] => Array
                (
                    [type] => text_textarea_with_summary
                    [settings] => Array
                        (
                            [rows] => 20
                            [summary_rows] => 5
                        )

                    [weight] => 31
                    [module] => text
                )

            [settings] => Array
                (
                    [display_summary] => 1
                    [text_processing] => 1
                    [user_register_form] => 
                )

            [display] => Array
                (
                    [default] => Array
                        (
                            [label] => hidden
                            [type] => text_default
                            [settings] => Array
                                (
                                )

                            [module] => text
                            [weight] => 0
                        )

                    [teaser] => Array
                        (
                            [label] => hidden
                            [type] => text_summary_or_trimmed
                            [settings] => Array
                                (
                                    [trim_length] => 600
                                )

                            [module] => text
                            [weight] => 0
                        )

                )

            [required] => 
            [description] => 
            [id] => 6
            [field_id] => 2
            [field_name] => body
            [entity_type] => node
            [bundle] => article
            [deleted] => 0
            [default_value] => 
        )

    [field_tags] => Array
        (
            [label] => Tags
            [description] => Enter a comma-separated list of words to describe your content.
            [widget] => Array
                (
                    [type] => taxonomy_autocomplete
                    [weight] => -4
                    [settings] => Array
                        (
                            [size] => 60
                            [autocomplete_path] => taxonomy/autocomplete
                        )

                    [module] => taxonomy
                )

            [display] => Array
                (
                    [default] => Array
                        (
                            [type] => taxonomy_term_reference_link
                            [weight] => 10
                            [label] => above
                            [settings] => Array
                                (
                                )

                            [module] => taxonomy
                        )

                    [teaser] => Array
                        (
                            [type] => taxonomy_term_reference_link
                            [weight] => 10
                            [label] => above
                            [settings] => Array
                                (
                                )

                            [module] => taxonomy
                        )

                )

            [settings] => Array
                (
                    [user_register_form] => 
                )

            [required] => 
            [id] => 7
            [field_id] => 3
            [field_name] => field_tags
            [entity_type] => node
            [bundle] => article
            [deleted] => 0
            [default_value] => 
        )

    [field_image] => Array
        (
            [label] => Image
            [description] => Upload an image to go with this article.
            [required] => 
            [settings] => Array
                (
                    [file_directory] => field/image
                    [file_extensions] => png gif jpg jpeg
                    [max_filesize] => 
                    [max_resolution] => 
                    [min_resolution] => 
                    [alt_field] => 1
                    [title_field] => 
                    [default_image] => 0
                    [user_register_form] => 
                )

            [widget] => Array
                (
                    [type] => image_image
                    [settings] => Array
                        (
                            [progress_indicator] => throbber
                            [preview_image_style] => thumbnail
                        )

                    [weight] => -1
                    [module] => image
                )

            [display] => Array
                (
                    [default] => Array
                        (
                            [label] => hidden
                            [type] => image
                            [settings] => Array
                                (
                                    [image_style] => large
                                    [image_link] => 
                                )

                            [weight] => -1
                            [module] => image
                        )

                    [teaser] => Array
                        (
                            [label] => hidden
                            [type] => image
                            [settings] => Array
                                (
                                    [image_style] => medium
                                    [image_link] => content
                                )

                            [weight] => -1
                            [module] => image
                        )

                )

            [id] => 8
            [field_id] => 4
            [field_name] => field_image
            [entity_type] => node
            [bundle] => article
            [deleted] => 0
        )

)

I want it to come as:

Array
(
  [body]=>Body
  [field_tags]=>Tags
  [field_image]=>Image
)

How can I achieve this using foreach loop. This array is coming from below code.

$serialize = field_info_instances('node',$form_state['values']['displays']['selected']);
    foreach ($serialize as $key => $value) {
        print_r($serialize);die;
    }
  • 写回答

2条回答 默认 最新

  • dongzhijing8202 2015-07-24 09:27
    关注

    Rewrite array saving keys but change value to label item

    $newarray = array_map(function($i) { return $i['label']; }, $array);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?