Добавил find в ArrayHelper

This commit is contained in:
Artem Vasilev 2022-11-09 19:27:35 +03:00
parent 84dd8b6dfd
commit 43fcb9f061

View File

@ -4,6 +4,12 @@ namespace Webmasterskaya\CryptoPro\Helpers;
class ArrayHelper class ArrayHelper
{ {
/**
* @param array $array
* @param callable $fn
*
* @return bool
*/
public static function any(array $array, callable $fn) public static function any(array $array, callable $fn)
{ {
foreach ($array as $value) foreach ($array as $value)
@ -17,6 +23,12 @@ class ArrayHelper
return false; return false;
} }
/**
* @param array $array
* @param callable $fn
*
* @return bool
*/
public static function every(array $array, callable $fn) public static function every(array $array, callable $fn)
{ {
foreach ($array as $value) foreach ($array as $value)
@ -29,4 +41,21 @@ class ArrayHelper
return true; return true;
} }
/**
* @param array $array
* @param callable $fn
*
* @return mixed|void
*/
public static function find(array $array, callable $fn)
{
foreach ($array as $key => $value)
{
if ($fn($value, $key, $array))
{
return $value;
}
}
}
} }