note 116301 added to function.array-column
| From: | hypxm at qq dot com | Date: | Tue, 09 Dec 2014 06:36:05 +0000 |
| Subject: | note 116301 added to function.array-column | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-201094@lists.php.net to get a copy of this message | ||
a simple solution:
function arrayColumn(array $array, $column_key, $index_key=null){
if(function_exists('array_column ')){
return array_column($array, $column_key, $index_key);
}
$result = [];
foreach($array as $arr){
if(!is_array($arr)) continue;
if(is_null($column_key)){
$value = $arr;
}else{
$value = $arr[$column_key];
}
if(!is_null($index_key)){
$key = $arr[$index_key];
$result[$key] = $value;
}else{
$result[] = $value;
}
}
return $result;
}
----
Server IP: 72.52.91.14
Probable Submitter: 113.65.190.182
----
Manual Page -- http://php.net/manual/en/function.array-column.php
Edit -- https://master.php.net/note/edit/116301
Del: integrated -- https://master.php.net/note/delete/116301/integrated
Del: useless -- https://master.php.net/note/delete/116301/useless
Del: bad code -- https://master.php.net/note/delete/116301/bad+code
Del: spam -- https://master.php.net/note/delete/116301/spam
Del: non-english -- https://master.php.net/note/delete/116301/non-english
Del: in docs -- https://master.php.net/note/delete/116301/in+docs
Del: other reasons-- https://master.php.net/note/delete/116301
Reject -- https://master.php.net/note/reject/116301
Search -- https://master.php.net/manage/user-notes.php