2
爲了簡化這個問題,假定每個單元格都有一個行名和一個列名,可以將您正確地映射到適當的單元格。我正在循環訪問數據庫記錄,併爲2D數組中的某些字段創建位置,以便返回給調用者。我的問題是如何判斷一個單元格是否已經存在於數組[rownName] [colName]?如何判斷一個特定的關鍵組合是否已經在PHP的多維關聯數組中?
這裏就是我試圖做一個高層次的看法:
//While there are more records:
while ($row = mysql_fetch_assoc($result)) {
//If this key doeesn't already exist in the return array,
//add this key/value pair.
//Proper logic for determining whether or not a cell has already been
//created for this record would go here...
$ret[$row['output_row_id']][$row['output_name']] = $row['output_value'];
}
預先感謝您所有的幫助,所以!
這完美地工作。我正在查看array_key_exists的文檔,它似乎不支持多維鍵。謝謝! – 2009-10-14 20:56:57