Awesome array manipulation utility for PHP

#️⃣What is ArrayUtils?

ArrayUtils is a library that provides a great way to manipulate arrays.

The evil PHP array functions give developers the pain of:

  • Some functions requires array first, but some functions require array last...

  • Some functions returns result, but some functions modify referenced variables...

  • Code was line-break because since it is a the function...

  • Each function has different parameters to the callback function...

  • No modern functions using arrays. Such as every, some

I created this library to solve these problems and make code flow like js-array

#️⃣What happens when I use it?

Processing arrays through this library makes the code flow much clearer than pure PHP.

Pure PHP's array functions, when nested, reverse the code and get deeper and deeper indentations.

ArrayUtils solves these problems and makes the code easier to figure out.

Also, if you Using the arrow-function added in PHP 7.4, you can write more neatly.

$playerFiles = scandir(Server::getInstance()->getDataPath() . "players/";
$onlinePlayers = Server::getInstance()->getOnlinePlayers();

$onlineNames = array_column(
        function(Player $player) : array{ return [strtolower($player->getName()), $player->getName()]; },
    ), 1, 0
$playerNames = array_column(
        function(string $playerName) : array{ return [strtolower($playerName), $playerName]; },
            function(string $playerName) use($onlineNames) : string{ return $onlineNames[strtolower($playerName)] ?? $playerName; },
                function(string $fileName) : string{ return substr($fileName, 0, -strlen(\".dat\")); },
                array_filter($playerFiles, function(string $fileName) : bool{ return substr($fileName, -strlen(\".dat\")) === \".dat\"; })
    ), 1, 0

Last updated