for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace App\Utils;
use Closure;
use InvalidArgumentException;
class ArrayUtils {
public static function apply(array &$items, Closure $closure): void {
foreach($items as $item) {
$closure($item);
}
public static function createArray(array $keys, array $values): array {
$array = [ ];
$count = count($keys);
$keys = array_values($keys);
$values = array_values($values);
if(count($keys) !== count($values)) {
throw new InvalidArgumentException('$keys and $items parameter need to have the same length.');
for($i = 0; $i < $count; $i++) {
$array[$keys[$i]] = $values[$i];
return $array;
public static function createArrayWithKeys(array $items, Closure $keyFunc): array {
$key = $keyFunc($item);
$array[$key] = $item;