gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 15:02:46 24 4
gpt4 key购买 nike

我的代码看起来像这样(完整代码有 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'];

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

最佳答案

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

关于php - 如何在几行代码中将大量数组键重构为对象属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22544901/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com