0

I have a scenario where I have $record variable. My loop contains keys which are then parsed like $record->{$key}. $keys variable contains ['title', 'date', 'user->name'].

Actually $record variable is a multi-dimensional object and it works fine until I have a key named as 'user->name'. What I want is to parse it as $record->user->name which I am unable to do.

$keys = ['title', 'date', 'location', 'user->name'];

foreach ($keys as $key) {
    echo $record->{$key};
}
Salman Khimani
  • 515
  • 2
  • 7
  • 21

0 Answers0