-1

I've an array called $data as follows:

Array
(
    [0] => Array
        (
            [pt_doc_id] => 22
            [pt_id] => 4
            [pt_doc_title] => Sahil Kumar
            [pt_doc_file_iname] => sahil_kumar.pdf
            [pt_doc_added_date] => 1390802339
            [pt_doc_updated_date] => 1390892061
        )

    [1] => Array
        (
            [pt_doc_id] => 23
            [pt_id] => 4
            [pt_doc_title] => Vijay Singh
            [pt_doc_file_iname] => vijay_singh.docx
            [pt_doc_added_date] => 1390802339
            [pt_doc_updated_date] => 1390892061
        )

)

The above array gets generated dynamically dpending upon the query fired. Sp the array length may vary. Now what I want to do is rename the array key ['pt_doc_file_iname'] to ['pt_doc_old_file_iname']. For every array element present within this array this change should take effect. Can anyone help me in this array manipulation? Thanks in advance.

PHPLover
  • 7,411
  • 36
  • 99
  • 184

1 Answers1

0

Use this:

foreach( $mainArray as &$arr ) {
  $arr["pt_doc_old_file_iname"] = $arr['pt_doc_file_iname'];
  unset( $arr['date'] );
}
unset($arr);

Now you will have the renamed keys

sergio
  • 5,190
  • 7
  • 23
  • 45