想知道是否有任何改進可以加快這個數組?如何改進這個php數組的數據檢索?
測試數組的行數是40,000條記錄。
循環完成需要很長時間。
樣本值:
$test[] = array(
'products_id' => $data['products_id'],
'products_extra_fields_id' => $data['products_extra_fields_id'],
'products_extra_fields_name' => $data['products_extra_fields_name'],
'products_extra_fields_value' => $data['products_extra_fields_value']
);
foreach productid
{
$colname="column name";
//this inside for loop making thing very slow
foreach ($test as $key1 => $row1)
{
$w= $row1['products_id'];
$x= $row1['products_extra_fields_id'];
$y= $row1['products_extra_fields_name'];
$z= $row1['products_extra_fields_value'];
if(($w==$products_id) && ($y== $colname))
{
$wantedvalue=$z;
break;
}
}
}
你有有重複$的機會數據[「products_id」] – Pete 2012-04-18 06:19:27
你有沒有想過使用一個數據庫呢? – bardiir 2012-04-18 06:21:05
我正在從數據庫中讀取數據,並且想在輸出爲excel之前正確格式化數據。直接查詢數據庫可能會更慢(資源密集) – 2012-04-18 06:23:07