Array
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
)
)
Need to rename the 'reg_date' to 'do_birth'
i've try to change the key but getting "Cannot use object of type stdClass as array" error.
foreach ($birth as $k => $v) {
$birth[$k] ['do_birth'] = $birth[$k] ['reg_date'];
unset($birth[$k]['reg_date']);
}
above few line of code not working for me!
You cannot get object as array use following code
foreach ($birth as $k => $v) {
$birth[$k]->do_birth = $birth[$k]->reg_date;
unset($birth[$k]->reg_date);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.