How to flatten array in PHP? -


i have array contains 4 arrays 1 value each.

array(4) {   [0]=>   array(1) {     ["email"]=>     string(19) "test01@testmail.com"   }   [1]=>   array(1) {     ["email"]=>     string(19) "test02@testmail.com"   }   [2]=>   array(1) {     ["email"]=>     string(19) "test03@testmail.com"   }   [3]=>   array(1) {     ["email"]=>     string(19) "test04@testmail.com"   } } 

what best (=shortest, native php functions preferred) way flatten array contains email addresses values:

array(4) {   [0]=>   string(19) "test01@testmail.com"   [1]=>   string(19) "test02@testmail.com"   [2]=>   string(19) "test03@testmail.com"   [3]=>   string(19) "test04@testmail.com" } 

in php 5.5 have array_column:

$plucked = array_column($yourarray, 'email'); 

otherwise, go array_map:

$plucked = array_map(function($item){ return $item['email'];}, $yourarray); 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -