douluan5738 2014-10-13 14:12
浏览 22
已采纳

获取PHP数组的值

I have this array which I would like to get the individual values of each item:

This is the result of print_r($theme_option):

Array ( [side_bars] => Array ( [0] => Array ( [title] => Left Page Sidebar [sort] => 0 ) [1] => Array ( [title] => Right Page Sidebar [sort] => ) [2] => Array ( [title] => Left Blog Sidebar [sort] => ) [3] => Array ( [title] => Right Blog Sidebar [sort] => ) )

I can get at a single sidebar name by using:

$theme_option['side_bars'][0]['title'];

I tried to loop through and get the individual sidebars using this code but it doesn't return as expected.

global $theme_option; 

    if(isset($theme_option['side_bars']) && is_array($theme_option['side_bars'])){
        foreach ($theme_option['side_bars'] as $key => $value) {
            $theme_side_bars["$key"] = "$value";
        }
    }

What I ant to try and do is get the value of each "Sidebar" and place the "title" into a dropdown box.

Thanks

  • 写回答

1条回答 默认 最新

  • dongniaoli1822 2014-10-13 14:16
    关注

    There is an array side_bars which contains an array with all the special infos.

    With this code you should have an array with all titles stored in the variable $theme_side_bars.

    global $theme_option; 
    $theme_side_bars = array();
    if(isset($theme_option['side_bars']) && is_array($theme_option['side_bars'])){
        foreach ($theme_option['side_bars'] as $index=>$arr) {
            $theme_side_bars[] = $arr['title'];
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部