I have 20+ sets of 30+ variables whose variable names are quite similar and I would like to dynamically set the variable names, but I'm having a bit of trouble applying the methods I know, such as creating a Variable Variables
or str_replace
to this particular scenario.
Sample Set:
$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'];
}
You can loop through the columns and set variable variables.
foreach ($rows as $row) {
foreach ($row as $colname => $value) {
$$colname = $value;
}
}