4个回答
2018-05-15 · 知道合伙人养生行家
关注
展开全部
array_slice($arr,1,-1);截取出来再改;
参考例子,完整写法:
$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
)
)
参考例子,完整写法:
$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
)
)
展开全部
按照你的图所示,应该这样写
$Line[$huoche[$i]] = $i;
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2015-04-05
展开全部
很简单的。稍稍改下就可以了
<?php
$line[str_replace(array('始','终'),'',$huoce[$i])] = $i;
// http://www.hi-docs.com/php-array.html
?>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
$Line[$huoche[$i]]=$i;[]
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询