>数组
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']);
}
上面几行代码对我不起作用!
不能使用以下代码将对象作为数组获取
foreach ($birth as $k => $v) {
$birth[$k]->do_birth = $birth[$k]->reg_date;
unset($birth[$k]->reg_date);
}