class Item
{
private $_SomeArray = array();
private $elementOfanArray;
function __construct()
{
$this->_SomeArray[0]="default message";
$this->elementOfanArray=0; //I am trying to assign empty value to an var
}
public function getArray()
{
return $this->SomeArray; //function returning whole array
}
public function setArray(elementOfanArray) //function for adding new element to an array and checking if not empty
{
if(!elementOfanArray)
{
}
else
{
array_push($_SomeArray, elementOfanArray);
$elementOfanArray = 0; //I am trying to assign value after addding element to an array
}
}
function __destruct(){
$this->_SomeArray;
$this->elementOfanArray;
}
}
这是我的代码,但现在我想知道如果使用“array_push”是正确的选择,因为它会被调用大约20次。 函数调用的数量不是恒定的,所以如果将有更少的值..我想将它们从数组中删除或只是立即转储它们。将新元素传递给类中的数组并返回其值
我得到的另一个问题是我应该如何从这个类中获取我的元素,是否有一种方法可以获得整个数组以外的值?
这就是我写的吗?
如果你调用从变量你需要使用'$ this->' – Naruto