News新闻

业界新闻动态、技术前沿
Who are we?

您的位置:首页      乐道系统FAQ      php修改数组键名的方法示例

php修改数组键名的方法示例

发布日期:2017-04-15 00:00:00 79

本文实例讲述了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);