PHPackages                             phpwatch/array\_key\_first\_last-polyfill - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. phpwatch/array\_key\_first\_last-polyfill

Abandoned → [symfony/polyfill-php73](/?search=symfony%2Fpolyfill-php73)ArchivedLibrary[Utility &amp; Helpers](/categories/utility)

phpwatch/array\_key\_first\_last-polyfill
=========================================

A simple polyfill to make PHP 7.3's array\_key\_first and array\_key\_last functions available to all.

21.2k2PHP

Since Nov 27Pushed 3y ago2 watchersCompare

[ Source](https://github.com/PHPWatch/array_key_first_last-polyfill)[ Packagist](https://packagist.org/packages/phpwatch/array_key_first_last-polyfill)[ RSS](/packages/phpwatch-array-key-first-last-polyfill/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependenciesVersions (1)Used By (0)

array\_key\_first\_last Polyfill
================================

[](#array_key_first_last-polyfill)

A polyfill to bring the [PHP 7.3 `array_key_first`](https://www.php.net/manual/en/function.array-key-first.php) and [PHP 7.3 `array_key_last`](https://www.php.net/manual/en/function.array-key-last.php) functions to PHP 5.3 and later.

**All PHP 7 versions are now EOL, and to lessen the upgrade gap, this project is now archive on GitHub, and marked as abandoned on Packagist. It will continue to work, but applications that depend this polyfill are strongly recommended to migrate to PHP 8 or later**.

[![Latest Stable Version](https://camo.githubusercontent.com/177256763753f99bc4880b44b2e3cd1bf9bd5dad48c78bdebc5ab23179e88e25/68747470733a2f2f706f7365722e707567782e6f72672f70687077617463682f61727261795f6b65795f66697273745f6c6173742d706f6c7966696c6c2f762f737461626c65)](https://packagist.org/packages/phpwatch/array_key_first_last-polyfill) [![License](https://camo.githubusercontent.com/d183ef229e9b3a8ff316247d3ab628c632d56eb7d4c43736f161e16b39f0ff95/68747470733a2f2f706f7365722e707567782e6f72672f70687077617463682f61727261795f6b65795f66697273745f6c6173742d706f6c7966696c6c2f6c6963656e7365)](https://github.com/phpwatch/array_key_first_last-polyfill) [![CI](https://github.com/phpwatch/array_key_first_last-polyfill/workflows/CI/badge.svg)](https://github.com/phpwatch/array_key_first_last-polyfill/actions)

Synopsis
--------

[](#synopsis)

This library provides a compatible layer to bring `array_key_first` and `array_key_last` functions that come with PHP 7.3. They provide the full functionality, but from user-land PHP code. Note that PHP 7.3's built-in these above functions are fast and memory-friendly because it is written in C language. However, if you have a library that requires these functions, you can use this library to transparently bring that functionality to any PHP version 5.3 or later.

Prerequisites
-------------

[](#prerequisites)

- PHP 5.3 or later.

Installing
----------

[](#installing)

The simplest way would be to install using [composer](https://getcomposer.org).

```
composer require phpwatch/array_key_first_last-polyfill
```

If the `array_key_first` and `array_key_last` functions are not available in your system, composer autoloader will seamlessly autoload a file provided by this library to provide the same functionality.

If you cannot use Composer, try convincing whoever made that decision it is not 2012 anymore. If that doesn't work, you can manually load these functions in the `src/` directory.

Usage
-----

[](#usage)

Usage is exactly the same as PHP 7.3 native `array_key_first` and `array_key_last` functions.

Make sure that the file is included. If you use Composer, include its autoload file. If the `array_key_first` and `array_key_last` functions is natively available, this library will not be loaded at all. If you do not use Composer autoloader, you will need to manually `require` the files in the `src` directory.

Here is an example of using `array_key_first` and `array_key_last` functions. The example below should work in any PHP version from 5.3 and later, even the `array_key_first` and `array_key_last` functions is not natively available.

```
$array = array(1, 2, 3, 4, 5, 6);
$firstKey = array_key_first($array); // 0
$lastKey = array_key_last($array); // 5
```

Development, tests, and contributing
------------------------------------

[](#development-tests-and-contributing)

Contributions are welcome. Please open an issue or send a pull-request. Please make sure to run the tests in both Linux-based platforms and Windows. Windows uses CRLF line endings, which can make tests fail if you hardcode the assertions to expect a specific position within an LF/CR-preferred platform.

Please note that tests and other deveopment dependencies are not included when you download the zip files from Github. This is to keep the library size small. You need to clone the repository or fork it to get the full source.

Credits
-------

[](#credits)

- [@Ayesh](https://github.com/Ayesh): [Ayesh Karunaratne](https://ayesh.me).
- [@peter279k](https://github.com/peter279k): [Chun-Sheng, Li](https://peterli.website/).

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity24

Early-stage or recently created project

 Bus Factor1

Top contributor holds 64.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/811553?v=4)[Ayesh Karunaratne](/maintainers/Ayesh)[@Ayesh](https://github.com/Ayesh)

---

Top Contributors

[![Ayesh](https://avatars.githubusercontent.com/u/811553?v=4)](https://github.com/Ayesh "Ayesh (11 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (5 commits)")[![gfilippakis](https://avatars.githubusercontent.com/u/28734506?v=4)](https://github.com/gfilippakis "gfilippakis (1 commits)")

---

Tags

phppolyfill

### Embed Badge

![Health badge](/badges/phpwatch-array-key-first-last-polyfill/health.svg)

```
[![Health](https://phpackages.com/badges/phpwatch-array-key-first-last-polyfill/health.svg)](https://phpackages.com/packages/phpwatch-array-key-first-last-polyfill)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
