array_intersect_assoc

Supported Versions: PHP 4 >= 4.3.0, PHP 5, PHP 7, PHP 8
Computes the intersection of arrays with additional index check
<?php array_intersect_assoc(array $array, array ...$arrays): array
<?php     public function intersectAssoc($items)

    {

        return new static(array_intersect_assoc($this->items, $this->getArrayableItems($items)));

    }
<?php         $random = Arr::random(['one' => 'foo', 'two' => 'bar', 'three' => 'baz'], 2, true);

        $this->assertIsArray($random);

        $this->assertCount(2, $random);

        $this->assertCount(2, array_intersect_assoc(['one' => 'foo', 'two' => 'bar', 'three' => 'baz'], $random));

    }



    public function testRandomNotIncrementingKeys()
<?php         $random = $data->random(2, true);

        $this->assertInstanceOf($collection, $random);

        $this->assertCount(2, $random);

        $this->assertCount(2, array_intersect_assoc($random->all(), $data->all()));



        $random = $data->random(fn ($items) => min(10, count($items)));

        $this->assertInstanceOf($collection, $random);
<?php         $random = $data->random(fn ($items) => min(10, count($items) - 1), true);

        $this->assertInstanceOf($collection, $random);

        $this->assertCount(5, $random);

        $this->assertCount(5, array_intersect_assoc($random->all(), $data->all()));

    }



    #[DataProvider('collectionClassProvider')]