Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. AbstractMap.php

function AbstractMap::putIfAbsent

Parameters

K $key The key to put in the map.:

T $value The value to store at `$key`.:

Return value

T | null the previous value associated with key, or `null` if there was no mapping for `$key`.

Overrides MapInterface::putIfAbsent

File

vendor/ramsey/collection/src/Map/AbstractMap.php, line 123

Class

AbstractMap
This class provides a basic implementation of `MapInterface`, to minimize the effort required to implement this interface.

Namespace

Ramsey\Collection\Map

Code

public function putIfAbsent(int|string $key, mixed $value) : mixed {
    $currentValue = $this->get($key);
    if ($currentValue === null) {
        $this[$key] = $value;
    }
    return $currentValue;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal