PHP 类内定义二维数组 并在后续程序中访问的问题

类定义如下:
class TimeRefresh
{
private $table=array(array());
public function InsertTable($r,$c,$str)
{
$table[$r][$c]=$str;
}
public function GetValue($r,$c)
{
$str=$table[$r][$c];
return $str;
}
}

值插入如下:
$str="abc";
$newStr="ddd";
$table->InsertTable(0,0,$str);
$table->InsertTable(0,1,$newStr);

值访问如下:(无法访问)
echo $table->GetValue(0,0)." ".$table->GetValue(0,1);

echo失败,提示:
<b>Notice</b>: Undefined variable: table in <b>C:\xampp\htdocs\qdb\output.php

<b>Notice</b>: Undefined variable: table in <b>C:\xampp\htdocs\qdb\output.php

请问该如何定义二维数组并且访问它 感谢
Initial时仍然提示 Undefined Variable: table
class TimeRefresh
{
private $table=array();

public function Initial()
{
for($i=0; $i<100; $i++)
{
$this->$table[$i][0]="null"; <--- 此行
$this->$table[$i][1]="null";
}
}
}
$table=new TimeRefresh();
$table->Initial();
Undefined variable: table

第1个回答  推荐于2016-09-29
class TimeRefresh
{
private $table=array();
public function InsertTable($r,$c,$str)
{
$this->table[$r][$c]=$str;
}
public function GetValue($r,$c)
{
$str=$this->table[$r][$c];
return $str;
}
}本回答被提问者采纳
第2个回答  2015-01-12
你方法是写在类里面 所以要初始化类
相似回答