php修改数组键名 php修改数组键名的方法示例
_海角 人气:1想了解php修改数组键名的方法示例的相关内容吗,_海角在本文为您仔细讲解php修改数组键名的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点: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程序设计有所帮助。
加载全部内容