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

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -