I have a class which reads in its initial values from a database table. Currently, I query the database to get the line of data, and pull out each specific value like 'name', 'size' and 'category' manually, by hard coding it into the constructor. These values are now fed into a 'details' array like:
$this->['Name'] = $DBRow->['Name']
and so on.
But to be more flexible, I would like to code it so that if I added extra columns to the database table, the class would automatically read the value into the array.
To do this, I need to iterate through each element in the $DBRow[] array, and copy it into the $this->Details[] array.
I guess I could just rename the $DBRow[] array itself to $this->Details[], but it would be wise to know how to copy an array value AND its key name
So how do I read the key names in an array? something like nameof( $this->DBRow[5]) ?
Thanks in advance!