Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

2d multidimensional array to 1d array in php [duplicate]

Just wondering if anyone has transformed a 2 dim array to a one dim array in php. I've yet to come across a clear explanation in php. Any suggestion would be appreciated.

like image 308
John Avatar asked Aug 02 '11 14:08

John


1 Answers

This might be helpful to you if you fetching values from Query here you can use array function which will support in PHP 5.5+

$myfield_arr = array_column($query_result, 'myfield_name');

Say Good bye to loop! Enjoy Smart Code.

like image 183
Nikunj Dhimar Avatar answered Oct 13 '22 09:10

Nikunj Dhimar