diff --git a/composer.json b/composer.json index f169946..270f6a3 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "description": "Utilities that make reading and writing PHP code more convenient and enjoyable", "type": "library", "license": "GPL-v2-or-later", - "version": "1.2.0", + "version": "1.2.1", "authors": [ { "name": "Elegant Themes", diff --git a/src/Utils.php b/src/Utils.php index 74cc2cc..4905fb2 100644 --- a/src/Utils.php +++ b/src/Utils.php @@ -131,21 +131,21 @@ public function _arraySortByCallback( $a, $b ): int { /** * Returns `true` if all values in `$array` are not empty, `false` otherwise. - * If `$condition` is provided then values are checked against it instead of `empty()`. + * If `$callback` is provided then values are passed to it instead of {@see empty()} (it should return a booleon value). * - * @param array $array - * @param bool $condition Compare values to this instead of `empty()`. Optional. + * @param array $array + * @param callable $callback Pass each value to callback instead of {@see empty()}. Optional. */ - public function all( array $array, $condition = null ): bool { - if ( null === $condition ) { + public function all( array $array, $callback = null ): bool { + if ( null === $callback ) { foreach( $array as $key => $value ) { if ( empty( $value ) ) { return false; } } - } else { + } else if ( is_callable( $callback ) ) { foreach( $array as $key => $value ) { - if ( $value !== $condition ) { + if ( ! $callback( $value ) ) { return false; } }