Coder Social home page Coder Social logo

array_key_first_last-polyfill's Introduction

array_key_first_last Polyfill

A polyfill to bring the PHP 7.3 array_key_first and PHP 7.3 array_key_last 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 License CI

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

  • PHP 5.3 or later.

Installing

The simplest way would be to install using composer.

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 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

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

array_key_first_last-polyfill's People

Contributors

ayesh avatar gfilippakis avatar peter279k avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

array_key_first_last-polyfill's Issues

Create README

As title, this polyfill needs a README markdown file.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.