0

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!

mathew
  • 86
  • 7

1 Answers1

2

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);
        }