in php remove keys and convert into a flat arrays -


i have array image shows , want remove key "holiday_date" , falt arry array('2010-01-01','2010-01-02',...) smarter way rather loop?

you need use array_column(),

$tmp = array_column($tmp, 'holiday_date'); 

this pull out 'holiday_date' values internal arrays, , storing them in $tmp itself, after line, $tmp formed need.


example: consider below array,

$records = array(     array(         'id' => 2135,         'first_name' => 'john',         'last_name' => 'doe',     ),     array(         'id' => 3245,         'first_name' => 'sally',         'last_name' => 'smith',     )); 

applying, array_column() below,

array_column($records, 'first_name'); 

will return,

array (     [0] => john     [1] => sally ) 

if using php version < 5.5, refer this quick implementation of array_column().


Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -