How does PHP modify the array key name? This article mainly introduces the method of PHP to modify the array key name, involving PHP for the traversal of the array, interception, conversion and other related operations skills, the need for friends can refer to. We hope to help you.
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< C6/>[type] = KKK ) [1] = = Array ([StaffID] [ wage] = [ Name] = King [Work] = LLL [Type] = TTT ) [2] = = Array ([StaffID] = [ wage] = [ Name] = + quit< C21/>[work] = QQQ [Type] = xxx ))
Related recommendations:
Summary of PHP array sorting methods
Ways to convert PHP arrays to and from strings
PHP array traversal foreach syntax structure and examples