HimmelKreis4865 / HashMap

A PHP Library that implements Java's Hashmap

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

HashMaps

HashMaps is a custom PHP Library that allows support for Java HashMaps in PHP.

Usage

use HashMap\HashMap;

require "HashMap.php";

$map = new HashMap("String", "String");

when constructing new HashMap(), you're passing two arguments.

The first argument is the expected type of the Key, this either be String, Integer or Float not case-sensitive

The second argument you pass is the expected type of the Value, you can see them in a table below

Type Name Alias
string String Str
float Float -
int Integer Int
array Array -
callable Callable Function
resource Resource Res
null Null -
bool Bool Boolean
object Object Obj
double Double -
long Long -

=> To add custom classes (or objects) you gotta use Classname::class, e.g.: Socket::class

Not case-sensitive

Documentation

Add a value to the hashmap

$hashmap->put($key, $value);

Get a value from the hashmap

$value = $hashmap->get($key);

Get a value from the hashmap with default values

$value = $hashmap->getOrDefault($key, $default);

Check if a key exists

$hashmap->contains($key);

Check if a value exists

$hashmap->containsValue($value);

Get Map size

$hashmap->size();

Remove a key from the Map

$hashmap->remove($key);

Go through all keys & values

$hashmap->forEach(function($key, $value) {

});

Get all values of the map

$values = $hashmap->getValues();

Get all keys of the map

$keys = $hashmap->keySet();

Replace a key in the map if the old value is not null

$hashmap->replace($key, $value);

Check if the map is empty

$hashmap->isEmpty();

Reset the whole map

$hashmap->clear();

About

A PHP Library that implements Java's Hashmap

License:GNU General Public License v3.0


Languages

Language:PHP 100.0%