PHPackages                             multidimensional/array-sanitization - 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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. multidimensional/array-sanitization

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

multidimensional/array-sanitization
===================================

Sanitize an array using rules from another array.

1.0.1(7y ago)0106MITPHPPHP &gt;=5.5

Since May 4Pushed 7y ago1 watchersCompare

[ Source](https://github.com/multidimension-al/array-sanitization)[ Packagist](https://packagist.org/packages/multidimensional/array-sanitization)[ RSS](/packages/multidimensional-array-sanitization/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (1)Dependencies (2)Versions (3)Used By (0)

Array Sanitization Library
==========================

[](#array-sanitization-library)

[![Build Status](https://camo.githubusercontent.com/bd78bcc5e6dfecfdea881cf19ac2861df442dc1c2e6eeb4a157bb325aab08d08/68747470733a2f2f7472617669732d63692e6f72672f6d756c746964696d656e73696f6e2d616c2f61727261792d73616e6974697a6174696f6e2e737667)](https://travis-ci.org/multidimension-al/array-sanitization)[![Latest Stable Version](https://camo.githubusercontent.com/07060d628d98d98d8023aae4e0a5a2a3004af0e84616c6e0249efd22cadf4656/68747470733a2f2f706f7365722e707567782e6f72672f6d756c746964696d656e73696f6e616c2f61727261792d73616e6974697a6174696f6e2f762f737461626c652e737667)](https://packagist.org/packages/multidimensional/array-sanitization)[![Code Coverage](https://camo.githubusercontent.com/88b3624cb0bf200710ff41fe9291436c62f320a8c3a9e939d0600501ff17c9b0/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d756c746964696d656e73696f6e2d616c2f61727261792d73616e6974697a6174696f6e2f6261646765732f636f7665726167652e706e67)](https://scrutinizer-ci.com/g/multidimension-al/array-sanitization/)[![Minimum PHP Version](https://camo.githubusercontent.com/dd6bad85ee03cf570f4cf82ab69a80396fdbf48050af932f8f23aa551b0d1e5a/687474703a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344253230352e352d3838393242462e737667)](https://php.net/)[![License](https://camo.githubusercontent.com/ad011cf1ace4287516403fe8f42005d36bb5b4940d23f621a4be1aba57c758df/68747470733a2f2f706f7365722e707567782e6f72672f6d756c746964696d656e73696f6e616c2f61727261792d73616e6974697a6174696f6e2f6c6963656e73652e737667)](https://packagist.org/packages/multidimensional/array-sanitization)[![Total Downloads](https://camo.githubusercontent.com/1078ea7ccd53d6362214733643314501f52d5ddfbf6b4d9d1cb21c20d87301e3/68747470733a2f2f706f7365722e707567782e6f72672f6d756c746964696d656e73696f6e616c2f61727261792d73616e6974697a6174696f6e2f642f746f74616c2e737667)](https://packagist.org/packages/multidimensional/array-sanitization)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/59993fab3cac48d2fbb7fb46a564f250f0c4812d5a2af7467513e70910a80770/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d756c746964696d656e73696f6e2d616c2f61727261792d73616e6974697a6174696f6e2f6261646765732f7175616c6974792d73636f72652e706e67)](https://scrutinizer-ci.com/g/multidimension-al/array-sanitization/)

This library sanitizes an array based on another array ruleset. The ruleset can have specific settings to force array values such as boolean, string, integer, decimal and others, as well as force regular expression pattern matching. This library is intended to be used as a compliment to our [Array Validation](https://github.com/multidimension-al/array-validation) library.

Requirements
------------

[](#requirements)

- PHP 5.5+

Installation
============

[](#installation)

The easiest way to install this library is to use composer. To install, simply include the following in your `composer.json` file:

```
"require": {
    "multidimensional/array-sanitization": "*"
}

```

Or run the following command from a terminal or shell:

```
composer require --prefer-dist multidimensional/array-sanitization

```

You can also specify version constraints, with more information available [here](https://getcomposer.org/doc/articles/versions.md).

Usage
=====

[](#usage)

This library utilizes PSR-4 autoloading, so make sure you include the library near the top of your class file:

```
use Multidimensional\ArraySanitization\Sanitization;
```

How to use in your code:

**Create Ruleset**

```
$rules = ['keyName' => ['type' => 'integer']];
```

**Sanitize an array against that ruleset**

```
$array = ['keyName' => 10.1];
$result = Sanitization::sanitize($array, $rules);
print_r ($result);

/*
 * $result = array('keyName' => 10);
 */
```

Advanced Rulesets
=================

[](#advanced-rulesets)

Specific ruleset examples can be found in the `SanitizationTest.php` file. For more advanced rulesets, view the [README.md](https://github.com/multidimension-al/array-validation/blob/master/README.md) from our [Array Validation](https://github.com/multidimension-al/array-validation) library.

Contributing
============

[](#contributing)

We appreciate all help in improving this library by either adding functions or improving existing functionality. If you do want to add to our library, please ensure you use PSR-2 formatting and add unit testing for all added functions.

Feel free to fork and submit a pull request!

License
=======

[](#license)

```
MIT License

Copyright (c) 2017 - 2019 multidimension.al

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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.

###  Release Activity

Cadence

Every ~657 days

Total

2

Last Release

2641d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/6588235?v=4)[AJ Quick](/maintainers/ajquick)[@ajquick](https://github.com/ajquick)

---

Top Contributors

[![ajquick](https://avatars.githubusercontent.com/u/6588235?v=4)](https://github.com/ajquick "ajquick (32 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/multidimensional-array-sanitization/health.svg)

```
[![Health](https://phpackages.com/badges/multidimensional-array-sanitization/health.svg)](https://phpackages.com/packages/multidimensional-array-sanitization)
```

###  Alternatives

[webmozart/assert

Assertions to validate method input/output with nice error messages.

7.6k894.0M1.2k](/packages/webmozart-assert)[bensampo/laravel-enum

Simple, extensible and powerful enumeration implementation for Laravel.

2.0k15.9M104](/packages/bensampo-laravel-enum)[swaggest/json-schema

High definition PHP structures with JSON-schema based validation

48612.5M73](/packages/swaggest-json-schema)[stevebauman/purify

An HTML Purifier / Sanitizer for Laravel

5325.6M19](/packages/stevebauman-purify)[ashallendesign/laravel-config-validator

A package for validating your Laravel app's config.

217905.3k5](/packages/ashallendesign-laravel-config-validator)[crazybooot/base64-validation

Laravel validators for base64 encoded files

1341.9M8](/packages/crazybooot-base64-validation)

PHPackages © 2026

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