2014-01-28 3 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); 

당신이 이름을 변경 키를해야합니다