How to refactor a large number of array keys to object properties in a few lines of code?

StackOverflow https://stackoverflow.com/questions/22544901

  •  18-06-2023
  •  | 
  •  

문제

I have code that looks like this (full code has 47 lines):

$this->outline->value         = $row['value'];
$this->outline->some_value    = $row['some_value'];
$this->outline->specs         = $row['specs'];
$this->outline->second_marker = $row['second_marker'];
$this->outline->holes         = $row['holes'];

How can I make this smaller while maintaining same functionality?

도움이 되었습니까?

해결책

foreach ($row as $key => $value) {
    $this->outline->{$key} = $value;
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top