好吧,我曾想过在 PHP 中使用 ArrayList,因为它在 PHP 中非常有用,并且可以节省大量时间。
我认为使用 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];
}
}
现在,我注意到我需要一个更多的列表类型 a hashmap
,所以我可以按键获取项目。假设我需要获取 mysql 数据库名称,所以我会这样做$data->hashmap->get("db_name")
。这将返回数据库名称值。
有没有办法做到这一点?