php访问多维数组中的特定数组值
问题描述:
Array
(
[2015] => Array
(
[0] => Array
(
[id] => 12
[title] => Story 12
[content] => Content of story
[date] => 2015-12-01
[featured] => 0
[source] => timeline_stories
)
[1] => Array
(
[id] => 2
[title] => Story 2
[content] => content of story
[date] => 2015-07-29
[featured] => 1
[source] => timeline_stories
)
)
[2014] => Array
(
[0] => Array
(
[id] => 3
[title] => Story 3
[content] => content 3
[date] => 2014-07-29
[featured] => 1
[source] => timeline_stories
)
)
)
我的数组具有以下结构,我按年分隔内容,使用array_keys()添加基于年的浮动菜单; 现在我需要在使用日期的年份附近添加月份智能菜单,如何访问每年的特定日期? 基本上每年提取日期列“日期”,并显示特定年份突出显示的所有月份。php访问多维数组中的特定数组值
答
采取这种方式,您有日期的数组,可以提取一个月
答
您可以使用array_map与array_walk得到的数据看http://php.net/manual/en/function.array-column.php
$year = 2014;
$dates = array_column($yourarray[$year], 'date');
。就像这样:
$menu_array = array_walk($data, function($year, &$item) {
$item = array_map(function($a) {
return date('m', strtotime($a['date']));
}, $item);
});
+0
我的数组名是$事件。我是新来的PHP,它给array_map():参数#2应该是一个数组错误 –
这工作得很好了手动fecthing但我要动态撷取日期,我有一大堆时间表内容 –