Having hash map (get by key) like in java in PHP?
Well I've thought of having ArrayList in PHP because it was extremely
useful in PHP, and saving a lot of time.
I thought it'd be cool to have in PHP, so I did make an arrayList class in
PHP:
Class ArrayList
{
public $arrayList;
function __construct()
{
$this->arrayList = array();
}
public function add($element)
{
$this->arrayList[] = $element;
}
public function remove($index)
{
if (is_numeric($index)) {
unset($this->arrayList[$index]);
}
}
public function get($index)
{
return $this->arrayList[$index];
}
}
Now, I noticed I need an list type more of a hashmap, so I can get items
by keys. Let's say I need to get mysql db name, so Ill just do
$data->hashmap->get("db_name"). This will return the database name value.
Is there a way to do this?
No comments:
Post a Comment