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条)

报告相同问题?

悬赏问题

  • ¥15 ansys fluent计算闪退
  • ¥15 有关wireshark抓包的问题
  • ¥15 需要写计算过程,不要写代码,求解答,数据都在图上
  • ¥15 向数据表用newid方式插入GUID问题
  • ¥15 multisim电路设计
  • ¥20 用keil,写代码解决两个问题,用库函数
  • ¥50 ID中开关量采样信号通道、以及程序流程的设计
  • ¥15 U-Mamba/nnunetv2固定随机数种子
  • ¥15 vba使用jmail发送邮件正文里面怎么加图片
  • ¥15 vb6.0如何向数据库中添加自动生成的字段数据。