Arr::only

Posted on November 16, 2016

The Arr::only function will return only the specified key / value pairs from the given array.

Example usage

$array = ['name' => 'Desk', 'price' => 100, 'orders' => 10];

$array = Arr::only($array, ['name', 'price']);

// ['name' => 'Desk', 'price' => 100]

$array1 = [
    ['id' => 1, 'name' => 'John Doe'],
    ['id' => 2, 'name' => 'Jane Doe'],
    ['id' => 3, 'name' => 'Jack Doe']
];

$array2 = Arr::only($array1, 1);

// [1 => ['id' => 2, 'name' => 'Jane Doe'] ]

Parameters

array $array

array|string $keys

Return Value

array

0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *