php如何修改陣列鍵名?本文主要介紹了php修改數組鍵名的方法,涉及php針對數組的遍歷、截取、轉換等相關操作技巧,所需的朋友可以參考下。希望對大家有幫助。
本文實例講述了php修改陣列鍵名的方法。分享給大家供大家參考,具體如下:
$ar = array( array(1 => 'a', 2 => 50, 3 => 60, 4 => 'long', 5 => 'zzz', 6 => 'kkk', 7 => 'ooo'), array(1 => 'b', 2 => 60, 3 => 70, 4 => 'king', 5 => 'lll', 6 => 'ttt', 7 => 'ppp'), array(1 => 'c', 2 => 70, 3 => 80, 4 => 'quit', 5 => 'qqq', 6 => 'xxx', 7 => 'ccc'), ); $kname = array('StaffId', 'Wage', 'Name', 'Work', 'Type'); function foo(&$v, $k, $kname) { $v = array_combine($kname, array_slice($v, 1, -1)); } array_walk($ar, 'foo', $kname); print_r($ar);
運行結果為:
Array ( [0] => Array ( [StaffId] => 50 [Wage] => 60 [Name] => long [Work] => zzz [Type] => kkk ) [1] => Array ( [StaffId] => 60 [Wage] => 70 [Name] => king [Work] => lll [Type] => ttt ) [2] => Array ( [StaffId] => 70 [Wage] => 80 [Name] => quit [Work] => qqq [Type] => xxx ) )
相關推薦:
以上是詳解php如何修改數組鍵名的詳細內容。更多資訊請關注PHP中文網其他相關文章!