php - How to extract particular fields from an array -
i have array looks
$articles = array([0] => array('title' => 'when ....', 'description' => '....', 'created' => '2011-02-21' ), [1] => array('title' => 'something ....', 'description' => 'when ....', 'created' => '2011-02-21' ), );
i want extract titles. there anyway retrieve titles without using , foreach loops. dont mind title becomes single string. thinking implode array adds description , created.
you can use example array_map
, why not want use loops? in fact every method, able modify array in way want it, iterate on it.
function reduce_to_title ($item) { return $item['title']; }; $titles = array_map('reduce_to_title', $articles);
or since php>=5.3
$titles = array_map(function ($item) { return $item['title']; }, $articles);
Comments
Post a Comment