phpcollection/phpcollection
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
phpoption/phpoption | 1.9.2 | - | Apache-2.0 | prod |
The PHP Collection is a general-purpose collection library for PHP, developed by Schmitt Johannes. It helps PHP developers to simplify and improve the manipulation of arrays and other data structures. This includes tasks such as filtering, sorting, and other operations usually performed on collections.
To use the PHP Collection library, you must first install it with Composer, a tool for dependency management in PHP. Here is how you do it:
composer require phpcollection/phpcollection
Then, you can use it in your code. Here is a simple example where we will create a sequence:
use JMS\PhpCollection\Sequence;
$sequence = new Sequence(array(1, 2, 3, 4));
$result = $sequence
->filter(function ($num) {
return $num % 2 == 0;
})
->map(function ($num) {
return $num * 2;
});
foreach ($result as $num) {
echo $num, "\n";
}
In this example, the code first initializes a sequence with the numbers from 1 to 4. Then, it filters out the odd numbers and doubles the remaining even numbers. At the end, it prints each number from the resulting sequence.
The documentation for the PHP Collection library can be found at its official documentation page. There, you can learn more about its functions and how you can use them in your PHP projects. The page includes all the necessary information to understand how to perform different operations with collections in PHP. The documentation is divided into several sections for easy navigation and it includes sample codes that make learning easier and quicker.