$arr = ...
$new_arr = array();
foreach ( $arr as $el ) {
$new_arr[] = $el['projects_users']['project_id'];
}
Or, with PHP version >= 5.3:
$new_arr = array_map(function ($e) { return $e['projects_users']['project_id']; }, $arr);
A third fun way, with reset:
$arr = ...
$new_arr = array();
foreach ( $arr as $el ) {
$new_arr[] = reset(reset($el));
}
###Performance
Out of curiosity / boredom I benchmarked the iterative / functional styles with and without reset. I was surprised to see that test 4 was the winner in every run — I thought that array_map had a bit more overhead than foreach, but (at least in this case) these tests show otherwise! Test code is here.http://pastie.org/2183604
$ php -v
PHP 5.3.4 (cli) (built: Dec 15 2010 12:15:07)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
$ php test.php
Test 1, Iterative - 34.093856811523 microseconds
Test 2, array_map - 37.908554077148 microseconds
Test 3, Iterative with reset - 107.0499420166 microseconds
Test 4, array_map with reset - 25.033950805664 microseconds
$ php test.php
Test 1, Iterative - 32.186508178711 microseconds
Test 2, array_map - 39.100646972656 microseconds
Test 3, Iterative with reset - 35.04753112793 microseconds
Test 4, array_map with reset - 24.080276489258 microseconds
$ php test.php
Test 1, Iterative - 31.948089599609 microseconds
Test 2, array_map - 36.954879760742 microseconds
Test 3, Iterative with reset - 32.901763916016 microseconds
Test 4, array_map with reset - 24.795532226562 microseconds
$ php test.php
Test 1, Iterative - 29.087066650391 microseconds
Test 2, array_map - 34.093856811523 microseconds
Test 3, Iterative with reset - 33.140182495117 microseconds
Test 4, array_map with reset - 25.98762512207 microseconds