Ds\Map::remove

(PECL ds >= 1.0.0)

Ds\Map::removeRemoves and returns a value by key

Beschreibung

public Ds\Map::remove(mixed $key, mixed $default = ?): mixed

Removes and returns a value by key, or return an optional default value if the key could not be found.

Hinweis:

Keys of type object are supported. If an object implements Ds\Hashable, equality will be determined by the object's equals function. If an object does not implement Ds\Hashable, objects must be references to the same instance to be considered equal.

Hinweis:

You can also use array syntax to access values by key, eg. $map["key"].

Achtung

Be careful when using array syntax. Scalar keys will be coerced to integers by the engine. For example, $map["1"] will attempt to access int(1), while $map->get("1") will correctly look up the string key.

See Arrays.

Parameter-Liste

key

The key to remove.

default

The optional default value, returned if the key could not be found.

Rückgabewerte

The value that was removed, or the default value if provided and the key could not be found in the map.

Fehler/Exceptions

OutOfBoundsException if the key could not be found and a default value was not provided.

Beispiele

Beispiel #1 Ds\Map::remove() example

<?php
$map 
= new \Ds\Map(["a" => 1"b" => 2"c" => 3]);

var_dump($map->remove("a"));      //  1
var_dump($map->remove("e"10));  // 10 (default used)
?>

Das oben gezeigte Beispiel erzeugt eine ähnliche Ausgabe wie:

int(1)
int(10)

Hier Kannst Du einen Kommentar verfassen


Bitte gib mindestens 10 Zeichen ein.
Wird geladen... Bitte warte.
* Pflichtangabe
Es sind noch keine Kommentare vorhanden.

PHP cURL-Tutorial: Verwendung von cURL zum Durchführen von HTTP-Anfragen

cURL ist eine leistungsstarke PHP-Erweiterung, die es Ihnen ermöglicht, mit verschiedenen Servern über verschiedene Protokolle wie HTTP, HTTPS, FTP und mehr zu kommunizieren. ...

TheMax

Autor : TheMax
Kategorie: PHP-Tutorials

Midjourney Tutorial - Anleitung für Anfänger

Über Midjourney, dem Tool zur Erstellung digitaler Bilder mithilfe von künstlicher Intelligenz, gibt es ein informatives Video mit dem Titel "Midjourney Tutorial auf Deutsch - Anleitung für Anfänger" ...

Mike94

Autor : Mike94
Kategorie: KI Tutorials

Grundlagen von Views in MySQL

Views in einer MySQL-Datenbank bieten die Möglichkeit, eine virtuelle Tabelle basierend auf dem Ergebnis einer SQL-Abfrage zu erstellen. ...

admin

Autor : admin
Kategorie: mySQL-Tutorials

Tutorial veröffentlichen

Tutorial veröffentlichen

Teile Dein Wissen mit anderen Entwicklern weltweit

Du bist Profi in deinem Bereich und möchtest dein Wissen teilen, dann melde dich jetzt an und teile es mit unserer PHP-Community

mehr erfahren

Tutorial veröffentlichen

Schwarzes Brett/ News Script

Informationen zu „Schwarzes Brett“ können nach Stichwort, Kategorie oder Veröffentlichungsdatum durchsucht werden. Die Informationen zum „ ...

Geschrieben von stuart99 am 25.08.2024 13:02:48
Forum: PHP Developer Forum
Schleifenproblem für MYSQL mit gleichen INPUT Feldnamen

It needs to be generic so it can run on any similar form. I've added a change event for every element in the form, but I'm not sure how to derive ...

Geschrieben von LarmanKhemka am 22.08.2024 07:20:22
Forum: PHP Developer Forum
PHPMail - Fatal error: Uncaught Error: Class not found

E-Mail senden scheint so weit zu funktionieren. Nur der Gmail-Server produziert ein timeout. Hat jemand da Einstellungen, die bei ihm funktioniert ...

Geschrieben von Lenno am 15.08.2024 16:23:06
Forum: PHP Developer Forum