Best to ask this with an example. I have a table with fields like ID, MeterA1, MeterA2, MeterA3, ReadingA1, ReadingA2, ReadingA3 etc. (I didn’t set this table up so de-normalised before you ask).
Rather than check each field for a value, I want to create a variable variable based on an abbreviated array and access the fields via that. What is the right way as this doesn’t work:
$array = array('A1', 'A2', 'A3');
while($row = $rec->fetch_object()) { // db record fetch
foreach($array as $meter) {
$result[$row->Meter{$meter}] = $row->Reading{$meter};
}
}
Thanks
1 Answer