compress.php
Table of Contents
Functions
- compress() : array<string|int, 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<string|int, mixed> $array[, array{clone?: bool, conditions?: callable|callable[], excludes?: string[], recursive?: bool, depth?: int|null, removeKeys?: string[], throwable?: bool}|null $options = [] ][, int $currentDepth = 0 ]) : array<string|int, 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<string|int, mixed>
-
The input array to compress.
- $options : array{clone?: bool, conditions?: callable|callable[], excludes?: string[], recursive?: bool, depth?: int|null, removeKeys?: string[], throwable?: bool}|null = []
-
Optional configuration.
- $currentDepth : int = 0
-
Internal counter used to track recursion depth.
Tags
Return values
array<string|int, mixed> —The compressed array (or its clone if clone=true).