你可以嘗試一下:
//Before while loop declare the array variable
$matrix = array();
While(your condition){
$matrix[] = array(
$_SESSION['review_buffer_name'],
$_SESSION['review_buffer_mail'],
$_SESSION['review_buffer_comment']
);
}
//To access array:
print_r($matrix[0]); //print_r whole first row. (array start from 0)
echo $matrix[0][0]; //echo single data that first row's first data
或者你可以設置索引像名稱:
//Before while loop declare the array variable
$matrix = array();
While(your condition){
$matrix[] = array(
'review_buffer_name'=>$_SESSION['review_buffer_name'],
'review_buffer_mail'=>$_SESSION['review_buffer_mail'],
'review_buffer_comment'=>$_SESSION['review_buffer_comment']
);
}
//Then access array:
print_r($matrix[0]); //print_r whole first row. (array start from 0)
echo $matrix[0]['review_buffer_name']; // first row's first data
分享你的while循環?你究竟想要做什麼?描述使用$矩陣數組。 – AHJeebon
$矩陣應該存儲多行數組...問題是當我訪問$矩陣[2],然後它給第二個數組的值...而不是數組的第二個記錄 –
因爲你的'$矩陣'是一個通常的列表,它似乎並沒有將任何東西附加到結果集合中。如果特定的語句在'while'中,你總是重寫'$ matrix'變量。嘗試使用'$ matrix [] = [...];'並查看更改或共享更多代碼。 –