我相信这就是您正在寻找的:
class Maker
{
private $arrayContainer = []; // Make public if you want to access it `$maker->arrayContainer`
function set(string $key, $value = [])
{
$this->arrayContainer[$key] = $value;
}
function get(string $key,$default=null){
return isset($this->arrayContainer[$key])?$this->arrayContainer[$key]:$default;
}
function all(){
return $this->arrayContainer;
}
}
$maker = new Maker();
$maker->set('a');
$maker->set('b', [1,2,3,4,5]);
$maker->set('c', ['a'=>1,'b'=>2,'c'=>3]);
//Get a specific index from the Maker class
print_r($maker->get('b'));
//Get the arrayContainer from the Maker Class
print_r($maker->all());
希望这可以帮助,