2016-08-03 138 views
-3
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訪問多維數組中的特定數組值

回答

0

採取這種方式,您有日期的數組,可以提取一個月

+0

這工作得很好了手動fecthing但我要動態擷取日期,我有一大堆時間表內容 –

0

您可以使用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應該是一個數組錯誤 –