【发布时间】:2015-11-03 11:00:59
【问题描述】:
我想在 [Price] 等某些键中将 , 替换为 .。
给定这个数组:
Array
(
[0] => Array
(
[Product line] => Misc
[Seller] => aaa.com
[Tracking ID] => bbbb
[Date shipped] => October 23, 2015
[Price] => 60,43
[Referral fee rate] => 3,00%
[Quantity] => 2
[Revenue] => 120,86
[Earnings] => 3,62
[Sub Tag] => xxxx
)
[1] => Array
(
[Product line] => Misc
[Seller] => aaaa.com
[Tracking ID] => bbbb
[Date shipped] => October 23, 2015
[Price] => 9,34
[Referral fee rate] => 6,96%
[Quantity] => 1
[Revenue] => 9,34
[Earnings] => 0,65
[Sub Tag] => xxxx
)
)
还有以下功能:
function str_replace_specific_value($sSearch, $sReplace, &$aSubject){
foreach($aSubject as $sKey => $uknValue) {
if(is_array($uknValue)) {
foreach($sKey as $fKey => $fuknValue) {
$uknValue['Price'] = str_replace($sSearch, $sReplace, $fuknValue);
}
}
}
}
有人可以帮帮我吗?我尝试了几件事,但无法正常工作。
【问题讨论】:
-
谢谢,你能看看我刚刚发布的功能吗?我很接近了,但还是有问题
-
为什么不使用
array_walk_recursive(),而不是所有的循环? (查看 cmets 了解如何在回调函数中更改数组) -
附带说明,您应该真正从函数中返回修改后的数组,而不是通过引用发送原始数组;您当前的方法使测试和故障排除变得非常困难。
-
@Uchiha 我试过了,但它不起作用,输出仍然是逗号而不是点。
标签: php arrays multidimensional-array str-replace