嗯,我想过在PHP中使用ArrayList,因为它在PHP中非常有用,并节省了大量时间。在PHP中使用哈希映射(通过键获取)和java一样?
我认为这会是很酷的PHP中,所以我做使PHP ArrayList类:
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];
}
}
现在,我发现我需要一个hashmap
的列表类型多,这样我就可以通过钥匙获取物品。 假设我需要获取mysql db名称,所以我只是做$data->hashmap->get("db_name")
。 这将返回数据库名称值。
有没有办法做到这一点?