I have a CSV file which needs to be processed into objects.
I can open the CSV file and get all the contents that I want, no problem there. I need to match the contents of the CSV file by headers into objects. For example:
Name | Address.Street | Address.Country | Notes.Example.Value
Object->Name
Object->Address
Object->Notes
etc.
How would I handle this dynamically, not knowing what the headers are going to be beforehand?
Essentially I want to turn a string, like "Prop.Prop.Prop.etc" into a nested object.
$headers = array(); // First row of CSV.
$row = array(); // Current row of CSV.
$record = new StdClass();
foreach ($row as $key => $value) {
$properties = explode('.', $headers[$key]);
if (count($properties > 1)) {
// ???
}
else {
$record->{$properties[0]} = $value;
}
}