如何在几行代码中将大量数组键重构为对象属性?

时间:2014-03-20 20:56:52

标签: php refactoring

我的代码看起来像这样(完整代码有47行):

$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'];

如何在保持相同功能的同时缩小尺寸?

1 个答案:

答案 0 :(得分:6)

foreach ($row as $key => $value) {
    $this->outline->{$key} = $value;
}