note 117684 added to function.array-column

From: Date: Tue, 21 Jul 2015 18:26:50 +0000
Subject: note 117684 added to function.array-column
Groups: php.notes 
Request: Send a blank email to php-notes+get-203156@lists.php.net to get a copy of this message
My version is closer to the original than http://github.com/ramsey/array_column <?php /** * Provides functionality for array_column() to projects using PHP earlier than * version 5.5. * @copyright (c) 2015 WinterSilence (http://github.com/WinterSilence) * @license MIT */ if (!function_exists('array_column')) { /** * Returns an array of values representing a single column from the input * array. * @param array $array A multi-dimensional array from which to pull a * column of values. * @param mixed $columnKey The column of values to return. This value may * be the integer key of the column you wish to retrieve, or it may be * the string key name for an associative array. It may also be NULL to * return complete arrays (useful together with index_key to reindex * the array). * @param mixed $indexKey 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. * @return array */ function array_column(array $array, $columnKey, $indexKey = null) { $result = array(); foreach ($array as $subArray) { if (!is_array($subArray)) { continue; } elseif (is_null($indexKey) && array_key_exists($columnKey, $subArray)) { $result[] = $subArray[$columnKey]; } elseif (array_key_exists($indexKey, $subArray)) { if (is_null($columnKey)) { $result[$subArray[$indexKey]] = $subArray; } elseif (array_key_exists($columnKey, $subArray)) { $result[$subArray[$indexKey]] = $subArray[$columnKey]; } } } return $result; } } ?> ---- Server IP: 72.52.91.14 Probable Submitter: 178.140.185.76 ---- Manual Page -- http://php.net/manual/en/function.array-column.php Edit -- https://master.php.net/note/edit/117684 Del: integrated -- https://master.php.net/note/delete/117684/integrated Del: useless -- https://master.php.net/note/delete/117684/useless Del: bad code -- https://master.php.net/note/delete/117684/bad+code Del: spam -- https://master.php.net/note/delete/117684/spam Del: non-english -- https://master.php.net/note/delete/117684/non-english Del: in docs -- https://master.php.net/note/delete/117684/in+docs Del: other reasons-- https://master.php.net/note/delete/117684 Reject -- https://master.php.net/note/reject/117684 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#203156) next »