note 119754 added to function.array-column
| From: | miguelfzarth at gmail dot com | Date: | Thu, 18 Aug 2016 14:02:17 +0000 |
| Subject: | note 119754 added to function.array-column | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-206313@lists.php.net to get a copy of this message | ||
<?php
# for PHP < 5.5
# AND it works with arrayObject AND array of objects
if (!function_exists('array_column')) {
function array_column($array, $columnKey, $indexKey = null)
{
$result = array();
foreach ($array as $subArray) {
if (is_null($indexKey) && array_key_exists($columnKey, $subArray)) {
$result[] = is_object($subArray)?$subArray->$columnKey: $subArray[$columnKey];
} elseif (array_key_exists($indexKey, $subArray)) {
if (is_null($columnKey)) {
$index = is_object($subArray)?$subArray->$indexKey: $subArray[$indexKey];
$result[$index] = $subArray;
} elseif (array_key_exists($columnKey, $subArray)) {
$index = is_object($subArray)?$subArray->$indexKey: $subArray[$indexKey];
$result[$index] = is_object($subArray)?$subArray->$columnKey:
$subArray[$columnKey];
}
}
}
return $result;
}
}
?>
----
Server IP: 72.52.91.14
Probable Submitter: 200.135.175.2
----
Manual Page -- http://php.net/manual/en/function.array-column.php
Edit -- https://master.php.net/note/edit/119754
Del: integrated -- https://master.php.net/note/delete/119754/integrated
Del: useless -- https://master.php.net/note/delete/119754/useless
Del: bad code -- https://master.php.net/note/delete/119754/bad+code
Del: spam -- https://master.php.net/note/delete/119754/spam
Del: non-english -- https://master.php.net/note/delete/119754/non-english
Del: in docs -- https://master.php.net/note/delete/119754/in+docs
Del: other reasons-- https://master.php.net/note/delete/119754
Reject -- https://master.php.net/note/reject/119754
Search -- https://master.php.net/manage/user-notes.php