{"id":19324872,"url":"https://github.com/spatie/array-functions","last_synced_at":"2025-05-15T05:06:02.422Z","repository":{"id":32326140,"uuid":"35901443","full_name":"spatie/array-functions","owner":"spatie","description":"Some handy array functions","archived":false,"fork":false,"pushed_at":"2025-02-14T10:40:47.000Z","size":65,"stargazers_count":244,"open_issues_count":0,"forks_count":40,"subscribers_count":14,"default_branch":"master","last_synced_at":"2025-04-10T10:09:56.676Z","etag":null,"topics":["array","functions","php"],"latest_commit_sha":null,"homepage":"https://spatie.be/opensource","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/spatie.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"spatie"}},"created_at":"2015-05-19T18:44:13.000Z","updated_at":"2025-04-04T04:40:43.000Z","dependencies_parsed_at":"2024-06-18T16:57:36.958Z","dependency_job_id":"d78819e0-1809-42bf-a3e3-1146889ac95e","html_url":"https://github.com/spatie/array-functions","commit_stats":{"total_commits":72,"total_committers":10,"mean_commits":7.2,"dds":0.4444444444444444,"last_synced_commit":"8ff57f1044015376ed1302a35c6cb745af515ac0"},"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Farray-functions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Farray-functions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Farray-functions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Farray-functions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/spatie","download_url":"https://codeload.github.com/spatie/array-functions/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254276447,"owners_count":22043867,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["array","functions","php"],"created_at":"2024-11-10T02:07:17.798Z","updated_at":"2025-05-15T05:05:57.405Z","avatar_url":"https://github.com/spatie.png","language":"PHP","funding_links":["https://github.com/sponsors/spatie"],"categories":[],"sub_categories":[],"readme":"# Some handy array functions\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/spatie/array-functions.svg?style=flat-square)](https://packagist.org/packages/spatie/array-functions)\n[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)\n[![Build Status](https://img.shields.io/travis/spatie/array-functions/master.svg?style=flat-square)](https://travis-ci.org/spatie/array-functions)\n[![Quality Score](https://img.shields.io/scrutinizer/g/spatie/array-functions.svg?style=flat-square)](https://scrutinizer-ci.com/g/spatie/array-functions)\n[![SensioLabsInsight](https://insight.sensiolabs.com/projects/860364d5-1d74-4cf8-bdb1-c5e18cdc8a70/mini.png)](https://insight.sensiolabs.com/projects/860364d5-1d74-4cf8-bdb1-c5e18cdc8a70)\n[![Total Downloads](https://img.shields.io/packagist/dt/spatie/array-functions.svg?style=flat-square)](https://packagist.org/packages/spatie/array-functions)\n\nThis package provides some handy array functions. \n\nSpatie is a webdesign agency in Antwerp, Belgium. You'll find an overview of all our open source projects [on our website](https://spatie.be/opensource).\n\n## Support us\n\n[\u003cimg src=\"https://github-ads.s3.eu-central-1.amazonaws.com/array-functions.jpg?t=1\" width=\"419px\" /\u003e](https://spatie.be/github-ad-click/array-functions)\n\nWe invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).\n\nWe highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).\n\n## Postcardware\n\nYou're free to use this package (it's [MIT-licensed](LICENSE.md)), but if it makes it to your production environment you are required to send us a postcard from your hometown, mentioning which of our package(s) you are using.\n\nOur address is: Spatie, Kruikstraat 22, 2018 Antwerp, Belgium.\n\nThe best postcards will get published on the open source page on our website.\n\n## Install\n\nYou can install this package via composer:\n\n``` bash\ncomposer require spatie/array-functions\n```\n\n## Usage\n\nThe following functions are provided in the `Spatie`-namespace:\n\n### array_rand_value\n```php\n/**\n * Get a random value from an array.\n *\n * @param array $array\n * @param int $numReq  The amount of values to return\n * @return mixed\n */\nfunction array_rand_value(array $array, $numReq = 1)\n```\n\n### array_rand_weighted\n```php\n/**\n * Get a random value from an array, with the ability to skew the results.\n * Example: array_rand_weighted(['foo' =\u003e 1, 'bar' =\u003e 2]) has a 66% chance of returning bar.\n * \n * @param array $key\n * \n * @return mixed\n */\nfunction array_rand_weighted(array $array)\n```\n\n### values_in_array\n```php\n/**\n * Determine if all given needles are present in the haystack.\n *\n * @param array|string $needles\n * @param array $haystack\n *\n * @return bool\n */\nfunction values_in_array($needles, array $haystack)\n```\n\n### array_keys_exist\n```php\n/**\n * Determine if all given needles are present in the haystack as array keys.\n * \n * @param array|string $needles\n * @param array $haystack\n *\n * @return bool\n */\nfunction array_keys_exist($needles, array $haystack)\n```\n\n### array_split_filter\n```php\n/**\n * Returns an array with two elements.\n * \n * Iterates over each value in the array passing them to the callback function.\n * If the callback function returns true, the current value from array is returned in the first\n * element of result array. If not, it is return in the second element of result array.\n *\n * Array keys are preserved.\n *\n * @param array $array\n * @param callable $callback\n * @return array\n *\n */\nfunction array_split_filter(array $array, callable $callback)\n```\n\n### array_split\n```php\n/**\n * Split an array in the given amount of pieces.\n *\n * @param array $array\n * @param int $numberOfPieces\n * @param bool $preserveKeys\n * @throws \\InvalidArgumentException\n * @return array\n */\nfunction array_split(array $array, $numberOfPieces = 2, $preserveKeys = false)\n```\n\n### array_merge_values\n```php\n/**\n * Returns an array with the unique values from all the given arrays\n *\n * @param \\array[] $arrays\n * @return array\n */\nfunction array_merge_values(array ... $arrays)\n```\n\n### array_flatten\n```php\n/**\n * Flatten an array of arrays. The `$levels` parameter specifies how deep you want to\n * recurse in the array. If `$levels` is -1, the function will recurse infinitely.\n *\n * @param array $array\n * @param int $levels\n *\n * @return array\n */\nfunction array_flatten(array $array, $levels = -1)\n```\n\n## Change log\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.\n\n## Testing\n\nYou can run the tests with:\n\n```bash\nvendor/bin/phpunit\n```\n\n## Contributing\n\nPlease see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.\n\n## Security\n\nIf you've found a bug regarding security please mail [security@spatie.be](mailto:security@spatie.be) instead of using the issue tracker.\n\n## Credits\n\n- [Freek Van der Herten](https://github.com/freekmurze)\n- [All Contributors](../../contributors)\n\n## About Spatie\nSpatie is a webdesign agency in Antwerp, Belgium. You'll find an overview of all our open source projects [on our website](https://spatie.be/opensource).\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspatie%2Farray-functions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspatie%2Farray-functions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspatie%2Farray-functions/lists"}