Home PHP Libraries Other libraries Laravel collection library for PHP
Laravel collection library for PHP
<?php
namespace Illuminate\Tests\Support;
use stdClass;
use ArrayAccess;
use Mockery as m;
use ReflectionClass;
use JsonSerializable;
use PHPUnit\Framework\TestCase;
use Illuminate\Support\Collection;
use Illuminate\Contracts\Support\Jsonable;
use Illuminate\Contracts\Support\Arrayable;
class SupportCollectionTest extends TestCase
{
    public function testFirstReturnsFirstItemInCollection()
    {
        $c = new Collection(['foo', 'bar']);
        $this->assertEquals('foo', $c->first());
    }
    public function testFirstWithCallback()
    {
        $data = new Collection(['foo', 'bar', 'baz']);
        $result = $data->first(function ($value) {
            return $value === 'bar';
        });
        $this->assertEquals('bar', $result);
    }

PHP's Laravel collection library is a library for obtaining a collection. A collection is equivalent to a table.

Disclaimer

All resources on this site are contributed by netizens or reprinted by major download sites. Please check the integrity of the software yourself! All resources on this site are for learning reference only. Please do not use them for commercial purposes. Otherwise, you will be responsible for all consequences! If there is any infringement, please contact us to delete it. Contact information: admin@php.cn

Related Article

laravel - What should the standardized PHP class library naming look like? laravel - What should the standardized PHP class library naming look like?

06 Jul 2016

I have seen many open source projects in the form of class.classname.php, but I have also seen many frameworks in the form of classname.class.php. Where should I place this class? I personally prefer the .class.php form, because in some frameworks, after importing third-party class libraries and specifying class libraries...

Which PHP ORM Library is Best for Abstracting Database Vendors and Mapping Domain/Relational Models? Which PHP ORM Library is Best for Abstracting Database Vendors and Mapping Domain/Relational Models?

05 Jan 2025

PHP ORM Library RecommendationsWhen it comes to object-relational mapping (ORM) for PHP, there are several libraries that stand out. To address...

PhpMailer vs. SwiftMailer: Which PHP Library Is the Best for Your Email Needs? PhpMailer vs. SwiftMailer: Which PHP Library Is the Best for Your Email Needs?

18 Oct 2024

PhpMailer vs. SwiftMailer: Comparing Email LibrariesWhen crafting a PHP script that requires email functionality, developers often face a choice between PhpMailer and SwiftMailer libraries. Navigating this decision can be crucial in finding the best

How Do I Link Static Libraries That Depend on Other Static Libraries? How Do I Link Static Libraries That Depend on Other Static Libraries?

13 Dec 2024

Linking Static Libraries to Other Static Libraries: A Comprehensive ApproachStatic libraries provide a convenient mechanism to package reusable...

What is the Most User-Friendly Form Validation Library for PHP with Comprehensive Features and Robust Error Handling? What is the Most User-Friendly Form Validation Library for PHP with Comprehensive Features and Robust Error Handling?

17 Oct 2024

Easiest Form Validation Library for PHPPHP boasts a plethora of validation libraries, each with its own strengths and weaknesses. To identify the ideal choice for your project, it's essential to consider factors such as simplicity, flexibility, and e

I finally tried Pest for PHP & Laravel, then made the switch I finally tried Pest for PHP & Laravel, then made the switch

30 Nov 2024

I started learning pure PHP in the middle of 2015. Then, I got familiar with CodeIgniter 3 and Laravel 5.1. Through the years, Laravel is my framework of choice, and I'm still sticking with it. Such as other popular PHP projects, I see PHPUnit is the

See all articles