请教 php 数组值替换 10
如题,我想替换两个相同键名数组的值:A数组:Array([Pro_Type]=>Array([0]=>INF8000S[1]=>INF8000S2)[Pro_Price]...
如题,我想替换两个相同键名数组的值:
A数组:Array ( [Pro_Type] => Array ( [0] => INF8000S [1] => INF8000S2 )
[Pro_Price] => Array ( [0] => 4080 [1] => 2100 ) [Pro_Num] => Array
( [0] => 1 [1] => 3 ) )
B数组:Array ( [ListNo] => 2014040206324260605 [pid] => 8 [tPrice] => 6180
[Pro_Type] => Array ( [0] => INF8000S [1] => INF8000S2 ) [Pro_Price]
=> Array ( [0] => 4080 [1] => 2100 ) [Pro_Num] => Array ( [0] =>
1 [1] => 1 ) )
用A数组的傎替换B数组中相同键名的值,替换完成后B数组变成:
Array ( [ListNo] => 2014040206324260605 [pid] => 8 [tPrice] => 6180 [Pro_Type] => Array ( [0] => INF8000S [1] => INF8000S2 ) [Pro_Price] => Array ( [0] => 4080 [1] => 2100 ) [Pro_Num] => Array ( [0] => 1 [1] => 3 ) ) 展开
A数组:Array ( [Pro_Type] => Array ( [0] => INF8000S [1] => INF8000S2 )
[Pro_Price] => Array ( [0] => 4080 [1] => 2100 ) [Pro_Num] => Array
( [0] => 1 [1] => 3 ) )
B数组:Array ( [ListNo] => 2014040206324260605 [pid] => 8 [tPrice] => 6180
[Pro_Type] => Array ( [0] => INF8000S [1] => INF8000S2 ) [Pro_Price]
=> Array ( [0] => 4080 [1] => 2100 ) [Pro_Num] => Array ( [0] =>
1 [1] => 1 ) )
用A数组的傎替换B数组中相同键名的值,替换完成后B数组变成:
Array ( [ListNo] => 2014040206324260605 [pid] => 8 [tPrice] => 6180 [Pro_Type] => Array ( [0] => INF8000S [1] => INF8000S2 ) [Pro_Price] => Array ( [0] => 4080 [1] => 2100 ) [Pro_Num] => Array ( [0] => 1 [1] => 3 ) ) 展开
5个回答
展开全部
php 的array_merge函数可以解决
$mergedArray = array_merge($arrayB, $arrayA);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
array_merge(A,B);
或者
foreache(B as $key=>$item){
A[ $key] = $item;
}
或者
foreache(B as $key=>$item){
A[ $key] = $item;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
B数组[键名] = A数组[键名]
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
array_place也能把
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
foreach($a as $key => $val) {
foreach($b as $keys => $values) {
if($key == $keys) {
$val == $values;
}
}
}
foreach($b as $keys => $values) {
if($key == $keys) {
$val == $values;
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询