How to find the maximum value in a numeric collection in illuminate/collections?

To find the maximum value in a numeric collection using the Illuminate Collections library, you can use the max method. Here is an example of how to do this:

  1. First, make sure you have the Illuminate Collections library installed in your project. You can install it using Composer by running the following command in your project directory:
composer require illuminate/collections
  1. In your PHP file, import the necessary classes:
use Illuminate\Support\Collection;
  1. Next, create a new Collection instance with your numeric values:
$collection = collect([1, 5, 2, 10, 3]);
  1. Finally, call the max method on the collection to retrieve the maximum value:
$maxValue = $collection->max();

The $maxValue variable will now contain the maximum value in the collection (in this case, 10).