This article mainly introduces PHP to modify the array key name method, involving PHP for array traversal, interception, conversion and other related operations skills, the need for friends can refer to the following
This article describes how PHP modifies the array key names. Share to everyone for your reference, as follows:
$ar = Array (Array (1 = ' a ', 2 = 3, 4 = ' long ', 5 = ' zzz ', 6 = ' kkk ', 7 = ' ooo '), Arra Y (1 = ' B ', 2 =, 3 =, 4 = ' King ', 5 = ' lll ', 6 = ' TTT ', 7 = ' PPP '), array (1 = ' C ', 2 = 3, 4 = ' quit ', 5 = ' QQQ ', 6 = ' xxx ', 7 = ' CCC '), $kname = Array (' StaffID ', ' wage ', ' Na Me ', ' work ', ' Type '), function foo (& $v, $k, $kname) {$v = Array_combine ($kname, Array_slice ($v, 1,-1));} Array_walk ($ar, ' foo ', $kname);p Rint_r ($ar);
The result of the operation is:
array ([0] = = Array ([StaffID] = [wage] = [Name] = Long [Work] = zzz [Type] = KKK) [1] = = Array ([StaffID] [wage] =&G T [Name] + king [Work] = LLL [Type] = TTT) [2] = = Array ([StaffID] + 70 [Wage] = [Name] + quit [Work] = QQQ [Type] + xxx))