HashMaps is a custom PHP Library that allows support for Java HashMaps in PHP.
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
$hashmap->put($key, $value);
$value = $hashmap->get($key);
$value = $hashmap->getOrDefault($key, $default);
$hashmap->contains($key);
$hashmap->containsValue($value);
$hashmap->size();
$hashmap->remove($key);
$hashmap->forEach(function($key, $value) {
});
$values = $hashmap->getValues();
$keys = $hashmap->keySet();
$hashmap->replace($key, $value);
$hashmap->isEmpty();
$hashmap->clear();