我想用.
代替,
,例如[Price]
。str_replace多維數組中的特定值
鑑於此陣:
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);
}
}
}
}
有人能幫助我嗎?我嘗試了一些東西,但無法使其工作。
謝謝,你可以去看看我剛剛發佈的功能?我很接近,但有些東西仍然不正確 – cliff
而不是所有的循環,爲什麼不使用['array_walk_recursive()'](http://php.net/array_walk_recursive)? (檢查註釋以查看如何更改回調函數中的數組) – kero
作爲一個側面提示,您應該真正從函數返回修改後的數組,而不是通過引用發送原始數據;您目前的方法使測試和故障排除非常困難。 – jeroen