【发布时间】:2020-09-12 09:48:21
【问题描述】:
数组
Array
(
[1] => stdClass Object
(
[id] => 1
[reg_type_id] => birth
[mem_tbl_id] => 1
[reg_date] => 1937-09-18
)
[2] => stdClass Object
(
[id] => 3
[reg_type_id] => birth
[mem_tbl_id] => 2
[reg_date] => 1945-02-06
)
[3] => stdClass Object
(
[id] => 4
[reg_type_id] => birth
[mem_tbl_id] => 3
[reg_date] => 1968-04-12
)
)
需要将“reg_date”重命名为“do_birth”
我尝试更改密钥,但出现“无法将 stdClass 类型的对象用作数组”错误。
foreach ($birth as $k => $v) {
$birth[$k] ['do_birth'] = $birth[$k] ['reg_date'];
unset($birth[$k]['reg_date']);
}
上面几行代码对我不起作用!
【问题讨论】:
-
$birth[$k]->do_birth = $birth[$k]->reg_date; -
如果此信息来自数据库,您可以尝试在列上使用别名来消除重命名值的需要。
标签: php codeigniter