Oihana PHP

omit.php

Table of Contents

Functions

omit()  : array<string|int, mixed>
Omits a set of keys from an array.

Functions

omit()

Omits a set of keys from an array.

omit(array<string|int, mixed> $array, array<string|int, mixed> $keys) : array<string|int, mixed>

This function is a semantic alias of removeKeys(). It returns a new array without the specified keys.

The naming is intentionally security- and data-filtering-oriented, making it well suited for excluding sensitive or unwanted fields (e.g. passwords, tokens, internal metadata).

Parameters
$array : array<string|int, mixed>

The input array to filter.

$keys : array<string|int, mixed>

The list of keys to omit from the array.

Tags
example
$data =
[
    'id'       => 42,
    'name'     => 'Alice',
    'email'    => 'alice@example.com',
    'password' => 'secret',
];

$result = omit( $data , [ 'password' , 'email' ] );

// [
//     'id'   => 42,
//     'name' => 'Alice',
// ]
see
removeKeys()
author

Marc Alcaraz (ekameleon)

since
1.0.8
Return values
array<string|int, mixed>

The filtered array without the specified keys.


        
On this page

Search results