Skip to content

Latest commit

 

History

History
44 lines (29 loc) · 526 Bytes

array_only.md

File metadata and controls

44 lines (29 loc) · 526 Bytes

Description

Return a subset of the array by passing in an array of keys to keep

array_only(array $array, array $keys): array

Parameters

array

The input array

keys

The keys to keep in the result

Returns

Returns a copy of the array with the keys kept and all others discarded.

Examples

Example # 1 Example uses of array_only()

print_r(
    array_only([
        'a' => 1, 
        'b' => 2
    ], ['a'])
);

The above example will output:

Array
(
    [a] => 1
)