Skip to content

Latest commit

 

History

History
37 lines (26 loc) · 684 Bytes

key.md

File metadata and controls

37 lines (26 loc) · 684 Bytes

key

Description

Returns the key of an item value in a collection or a default value in the case it does not exists

Parameters

value
Value to search in the collection.
coll
Collection where search the expected value.
default
Default value to return in the case that the value not exists (`null` if not provided).

Examples

Extract the optional value of a collection:

<?php

use function Lambdish\Phunctional\key;

$map = [
    'discount_1' => 10, 
    'discount_2' => 25,
    'discount_3' => 50,
    'discount_4' => 75,
];

return key(25, $map, 0); 
            
// => discount_2