PHP 8 reference · Array Functions
PHP array_all() Function
Return true if every element passes a callback test, stopping at the first failure. Added in PHP 8.4.
PHP 8 Since 8.4
Syntax
array_all(array $array, callable $callback): bool
Parameters
| Parameter | Description |
|---|---|
array |
The input array. |
callback |
fn($value, $key) returns true if the element passes. |
Return value
true if all elements pass.
Examples
<?php
$ages = [21, 34, 19];
var_dump(array_all($ages, fn($age) => $age >= 18));
Output
bool(true)
Run this on your computer — see “Get Started” for setup.
<?php
var_dump(array_all([], fn($v) => false)); // empty: true
Output
bool(true)
Run this on your computer — see “Get Started” for setup.
Version history
| Version | Change |
|---|---|
| PHP 8.4 | Added |
In other languages
all()· Pythonarray.every()· JavaScript
Related
array_any()· Return true if at least one element passes a callback test, stopping at the first match. Added in PHP 8.4.array_filter()· Keep only the elements for which a callback returns true. Without a callback it removes empty values; keys are kept.- PHP Array Functions · tutorial
- PHP Arrays · tutorial