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

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化