Illuminate\Support\Collection::combine PHP Method

combine() public method

Create a collection by using this collection for keys and another for its values.
public combine ( mixed $values ) : static
$values mixed
return static
    public function combine($values)
    {
        return new static(array_combine($this->all(), $this->getArrayableItems($values)));
    }

Usage Example

Exemplo n.º 1
0
 public function testCombineWithCollection()
 {
     $expected = [1 => 4, 2 => 5, 3 => 6];
     $keyCollection = new Collection(array_keys($expected));
     $valueCollection = new Collection(array_values($expected));
     $actual = $keyCollection->combine($valueCollection)->toArray();
     $this->assertSame($expected, $actual);
 }