php - how to get value array using key from array -


what want do

here main array

   array     (         [0] => array             (                 [culture] => array                     (                         [id] => 8                         [title] => test123                         [description] => test123                         [year] => 2012                         [photo] => test123.jpg                                                 [datetime] => 0000-00-00 00:00:00                         [status] => 0                     )              )          [1] => array             (                 [culture] => array                     (                         [id] => 9                         [title] => here title                         [description] => here title                         [year] => 2012                         [photo] => here.jpg                                                 [datetime] => 0000-00-00 00:00:00                         [status] => 0                     )              )          [2] => array             (                 [culture] => array                     (                         [id] => 11                         [title] => here title 2                         [description] => here title 2                         [year] => 2012                         [photo] => here.jpg                                                 [datetime] => 0000-00-00 00:00:00                         [status] => 0                     )              )          [3] => array             (                 [culture] => array                     (                         [id] => 12                         [title] => here title 3                         [description] => here title 3                         [year] => 2013                         [photo] => here.jpg                                                 [datetime] => 0000-00-00 00:00:00                         [status] => 0                     )              )          [4] => array             (                 [culture] => array                     (                         [id] => 13                         [title] => here title 4                         [description] => here title 4                         [year] => 2014                         [photo] => here.jpg                                                 [datetime] => 0000-00-00 00:00:00                         [status] => 0                     )              )          [5] => array             (                 [culture] => array                     (                         [id] => 14                         [title] => here title 5                         [description] => here title 5                         [year] => 2015                         [photo] => here.jpg                                                 [datetime] => 0000-00-00 00:00:00                         [status] => 0                     )              )                    ) 

now array want array of year (by key) like:

array ( [0]=>2012 [1]=>2013 [2]=>2014 [3]=>2015 ) 

loop through array , assign years new array keys intact.

$years=array(); foreach($yourarray $key=>$value) {    $years[$key]=$value["culture"]["year"]; } $years = array_unique($years); print_r($years); 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -