compress.php
Table of Contents
Functions
- compress() : array<int|string, mixed>
- Compress the given array by removing entries that match specified conditions.
Functions
compress()
Compress the given array by removing entries that match specified conditions.
compress(array<int|string, mixed> $array[, array{clone?: bool, conditions?: callable|array|string|null, excludes?: array|null, recursive?: bool, depth?: int|null, removeKeys?: array|null, throwable?: bool}|null $options = [] ][, int $currentDepth = 0 ]) : array<int|string, mixed>
This function traverses an array and removes elements according to the provided configuration. It can work recursively on nested arrays and objects, with optional depth limitation and key-based exclusions.
Useful for cleaning associative arrays (e.g., form data, object exports) by removing nulls, empty strings, or other unwanted values.
Parameters
- $array : array<int|string, mixed>
-
The input array to compress.
-
$options
: array{clone?: bool, conditions?: callable|array
|string|null, excludes?: array = []|null, recursive?: bool, depth?: int|null, removeKeys?: array |null, throwable?: bool}|null -
Optional configuration.
- $currentDepth : int = 0
-
Internal counter used to track recursion depth.
Tags
Return values
array<int|string, mixed> —The compressed array (or its clone if clone=true).