2010-08-02 92 views
1

我有矩陣和如何從那裏獲得價值?從文件獲得 的數據,從而使基體可以具有不同的尺寸php,從矩陣(數組)獲得值

由於

+3

你的加載代碼的樣本將是很好的。 – tdammers 2010-08-02 23:04:38

+2

你在說PHP中的二維數組嗎?如果你澄清你的問題,我們不會猜測。 – sholsapp 2010-08-02 23:05:16

回答

1

或CEO(因爲問題是模糊),如果讀入的內容,並具有存儲在一個兩結果二維數組,那麼您將使用括號來查找單元格值。例如,這裏的閱讀在內容製作成多維數組名爲$矩陣:

$contents = file_get_contents("myfile.csv"); 
$splitlines = explode("\n",$contents);//split the contents into rows 
$matrix = array(); 
foreach($splitlines as $line){ 
    $row = explode(",",$line);//split each line into columns 
    $matrix[] = $row;//add the array of columns as a new row in the matrix 
} 

現在解決任何值的矩陣:

$samplevalue = $matrix[2][1]; //addresses the third row, second column.