I have an array of arrays, with the following structure :
array(array(\'page\' => \'page1\', \'name\' => \'pagename1\')
array(\'page\' => \'pa
Well there is. At least for PHP > 5.5.0 and it is called array_column
The PHP function takes an optional $index_key
parameter that - as per the PHP website - states:
$index_key
The column to use as the index/keys for the returned array. This value may be the integer key of the column, or it may be the string key name
In the answers here, i see a stripped version without the optional parameter. I needed it, so, here is the complete function:
if (!function_exists('array_column')) {
function array_column($array, $column, $index_key = null) {
$toret = array();
foreach ($array as $key => $value) {
if ($index_key === null){
$toret[] = $value[$column];
}else{
$toret[$value[$index_key]] = $value[$column];
}
}
return $toret;
}
}