2014-01-28 46 views
-1

我调用$data阵列如下:如何重命名所有数组元素的关联数组中的键?

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 
     ) 

) 

上述数组被动态生成dpending在烧制该查询。 Sp的数组长度可能会有所不同。现在我想要做的是将数组密钥['pt_doc_file_iname']重命名为['pt_doc_old_file_iname']。对于数组中存在的每个数组元素,此更改应该生效。任何人都可以帮助我在这个数组操作?提前致谢。

+0

http://stackoverflow.com/questions/2212948/php-rename-array-keys-in-multidimensional-array –

+0

美丽的答案http://stackoverflow.com/questions/9605143/how-to-rename-array-keys-in-php –

回答

0

使用此:

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

现在你将有重命名的键