Arr::forget

Posted on November 16, 2016

The Arr::forget function removes a given key / value pair from a deeply nested array using "dot" notation.

Example usage

Arr::forget(
    ['products' => ['desk' => ['price' => 100]]],
    'products.desk'
);

// ['products' => []]

Arr::forget(
    [
        ['id' => 1, 'name' => 'John Doe'],
        ['id' => 2, 'name' => 'Jane Doe'],
    ],
    '0.id'
);

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

Arr::forget(
    [
        ['id' => 1, 'name' => 'John Doe'],
        ['id' => 2, 'name' => 'Jane Doe'],
    ],
    ['0.id', '1.name']
);

// [
//     ['name' => 'John Doe'],
//     ['id' => 2]
// ]

Parameters

array $array

array|string $keys

Return Value

void

0 Comments

Leave a Reply

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