douluan5738 2014-10-13 22: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 22: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'];
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度