php数组中插入新的元素
假设我有一个数组$arrs=Array([0]=>Array([id]=>1[rid]=>175[name]=>sdf[salary]=>sdf[accountNo]=>...
假设我有一个数组$arrs=Array
(
[0] => Array
(
[id] => 1
[rid] => 175
[name] => sdf
[salary] => sdf
[accountNo]=>000
)
[1] => Array
(
[id] => 2
[rid] => 175
[name] => wer
[salary] => wer
[accountNo]=>111
)
)
想把它变成
(
[0] => Array
(
[id] => 1
[rid] => 175
[accountNo]=>000
[name] => sdf
[salary] => sdf
)
[1] => Array
(
[id] => 2
[rid] => 175
[accountNo]=>111
[name] => wer
[salary] => wer
)
) 展开
(
[0] => Array
(
[id] => 1
[rid] => 175
[name] => sdf
[salary] => sdf
[accountNo]=>000
)
[1] => Array
(
[id] => 2
[rid] => 175
[name] => wer
[salary] => wer
[accountNo]=>111
)
)
想把它变成
(
[0] => Array
(
[id] => 1
[rid] => 175
[accountNo]=>000
[name] => sdf
[salary] => sdf
)
[1] => Array
(
[id] => 2
[rid] => 175
[accountNo]=>111
[name] => wer
[salary] => wer
)
) 展开
1个回答
展开全部
你好,看你意思是要在每个二维数组里插入新的数据
<?php
foreach($arrs as $each){
$each['name'] = 'wer';
$each['salary'] = 'wer'; //wer的值,可以自己动态调用
}
?>
希望能解决你的问题,还望采纳
更多追问追答
追问
我没有插入新的数据 是吧最后一行数据 放到中间了
追答
哦,对,我看错了
如下操作,先删除,后增加,就会放在后面了
<?php
foreach($arrs as $each){
$a = $each['accountNo'];
unset($each['accountNo']);
$each['accountNo'] = $a;
}
?>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询