├── CHANGELOG.md ├── LICENSE ├── README.md ├── composer.json └── src └── array_column.php /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # array_column() Changelog 2 | 3 | ## 1.1.3 4 | 5 | _Released 2015-03-20_ 6 | 7 | * Changing package name from "rhumsaa/array_column" to "ramsey/array_column" 8 | * Updated Travis CI build config to test more versions of PHP 9 | * Updated Travis CI config to lint and check PSR-2 coding standards 10 | * Added project badges 11 | * Added CHANGELOG 12 | 13 | ## 1.1.2 14 | 15 | _Released 2013-07-22_ 16 | 17 | * Remove unnecessary conditionals 18 | * Whitespace changes 19 | 20 | ## 1.1.1 21 | 22 | _Released 2013-07-06_ 23 | 24 | * Documentation updates 25 | 26 | ## 1.1.0 27 | 28 | _Released 2013-07-06_ 29 | 30 | * Catching up array_column() library functionality and tests with PHP 5.5.0 31 | * Set Travis CI to run tests on PHP 5.5 32 | 33 | ## 1.0.0 34 | 35 | _Released 2013-03-22_ 36 | 37 | * Initial release of userland library 38 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013-2015 Ben Ramsey (http://benramsey.com) 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # array_column() for PHP 2 | 3 | [![Build Status](https://travis-ci.org/ramsey/array_column.svg?branch=master)](https://travis-ci.org/ramsey/array_column) 4 | [![Coverage Status](https://coveralls.io/repos/ramsey/array_column/badge.svg?branch=master)](https://coveralls.io/r/ramsey/array_column) 5 | [![Latest Stable Version](https://poser.pugx.org/ramsey/array_column/v/stable.svg)](https://packagist.org/packages/ramsey/array_column) 6 | [![Total Downloads](https://poser.pugx.org/ramsey/array_column/downloads.svg)](https://packagist.org/packages/ramsey/array_column) 7 | [![Latest Unstable Version](https://poser.pugx.org/ramsey/array_column/v/unstable.svg)](https://packagist.org/packages/ramsey/array_column) 8 | [![License](https://poser.pugx.org/ramsey/array_column/license.svg)](https://packagist.org/packages/ramsey/array_column) 9 | 10 | This simple library provides functionality for [`array_column()`](http://php.net/array_column) 11 | to versions of PHP earlier than 5.5. It mimics the functionality of the built-in 12 | function in every way. 13 | 14 | 15 | ## Usage 16 | 17 | ``` 18 | array array_column(array $input, mixed $columnKey[, mixed $indexKey]) 19 | ``` 20 | 21 | Given a multi-dimensional array of data, `array_column()` returns the values 22 | from a single column of the input array, identified by the `$columnKey`. 23 | Optionally, you may provide an `$indexKey` to index the values in the returned 24 | array by the values from the `$indexKey` column in the input array. 25 | 26 | For example, using the following array of data, we tell `array_column()` to 27 | return an array of just the last names, indexed by their record IDs. 28 | 29 | ``` php 30 | 2135, 34 | 'first_name' => 'John', 35 | 'last_name' => 'Doe' 36 | ), 37 | array( 38 | 'id' => 3245, 39 | 'first_name' => 'Sally', 40 | 'last_name' => 'Smith' 41 | ), 42 | array( 43 | 'id' => 5342, 44 | 'first_name' => 'Jane', 45 | 'last_name' => 'Jones' 46 | ), 47 | array( 48 | 'id' => 5623, 49 | 'first_name' => 'Peter', 50 | 'last_name' => 'Doe' 51 | ) 52 | ); 53 | 54 | $lastNames = array_column($records, 'last_name', 'id'); 55 | ``` 56 | 57 | If we call `print_r()` on `$lastNames`, you'll see a resulting array that looks 58 | a bit like this: 59 | 60 | ``` text 61 | Array 62 | ( 63 | [2135] => Doe 64 | [3245] => Smith 65 | [5342] => Jones 66 | [5623] => Doe 67 | ) 68 | ``` 69 | 70 | 71 | ## Installation 72 | 73 | The easiest way to install this library is to use [Composer](https://getcomposer.org/): 74 | 75 | ``` 76 | php composer.phar require ramsey/array_column 77 | ``` 78 | 79 | Then, when you run `composer install`, everything will fall magically into place, 80 | and the `array_column()` function will be available to your project, as long as 81 | you are including Composer's autoloader. 82 | 83 | _However, you do not need Composer to use this library._ 84 | 85 | This library has no dependencies and should work on older versions of PHP. 86 | Download the code and include `src/array_column.php` in your project, and all 87 | should work fine. 88 | 89 | When you are ready to run your project on PHP 5.5, everything should 90 | continue to run well without conflicts, even if this library remains included 91 | in your project. 92 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ramsey/array_column", 3 | "description": "Provides functionality for array_column() to projects using PHP earlier than version 5.5.", 4 | "type": "library", 5 | "keywords": ["array", "column", "array_column"], 6 | "homepage": "https://github.com/ramsey/array_column", 7 | "license": "MIT", 8 | "authors": [ 9 | { 10 | "name": "Ben Ramsey", 11 | "homepage": "http://benramsey.com" 12 | } 13 | ], 14 | "support": { 15 | "issues": "https://github.com/ramsey/array_column/issues", 16 | "source": "https://github.com/ramsey/array_column" 17 | }, 18 | "abandoned": true, 19 | "require-dev": { 20 | "phpunit/phpunit": "~4.5", 21 | "squizlabs/php_codesniffer": "~2.2", 22 | "jakub-onderka/php-parallel-lint": "0.8.*", 23 | "satooshi/php-coveralls": "0.6.*" 24 | }, 25 | "autoload": { 26 | "files": ["src/array_column.php"] 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/array_column.php: -------------------------------------------------------------------------------- 1 |