gpt4 book ai didi

php - Codeigniter 将新键和值添加到 foreach 循环内的对象 (stdClass)

转载 作者:搜寻专家 更新时间:2023-10-31 21:06:37 25 4
gpt4 key购买 nike

我正在尝试将另一个键和值添加到 foreach 循环内的数组。我有以下数组。

    array (size=2)
0 =>
object(stdClass)[27]
public 'ID' => string '1' (length=1)
public 'sectiontitle' => string 'Personal Information' (length=20)
public 'field_format' => string 'vertical' (length=8)
public 'status' => string '1' (length=1)

和php代码

       foreach ($query->result() as $row) {
$data[] = $row;
}
var_dump($data);
return $data;

我想向其中添加键 [字段] 和值字符串。

最佳答案

试试这个

foreach ($query->result() as $row) {
$row->newKey = $newValue;
$data[] = $row;
}
var_dump($data);
return $data;

关于php - Codeigniter 将新键和值添加到 foreach 循环内的对象 (stdClass),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31285441/

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