Skip to content

Latest commit

 

History

History
35 lines (24 loc) · 638 Bytes

File metadata and controls

35 lines (24 loc) · 638 Bytes

get

Description

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

Parameters

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

Examples

Extract the optional value of a collection:

<?php

use function Lambdish\Phunctional\get;

$cart = [
    'price' => 100, 
    'money' => 'EUR',
];

return $cart['price'] - get('discount', $cart, 0); 
            
// => 100