0
我有20多組30+變量,其變量名稱非常相似,我想動態設置變量名稱,但我在應用我知道的方法,比如爲這個特定場景創建一個Variable Variables
或str_replace
。爲獲取的多列創建一個'變量變量'
樣本集:
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($rows as $row => $value) {
$Height_MIN_5A = $row['Height_MIN_5A'];
$Height_MIN_5B = $row['Height_MIN_5B'];
$Height_MIN_4A = $row['Height_MIN_4A'];
$Height_MIN_4B = $row['Height_MIN_4B'];
$Height_MIN_4C = $row['Height_MIN_4C'];
}
任何時候你認爲你需要變量變量,你可能應該使用關聯數組。 – Barmar
每次通過循環覆蓋相同的變量。這應該如何工作? – Barmar
而'$ row ['columnname']'應該是'$ value ['columnname']''。 '$ row'只是行號。 – Barmar