我有一个包含三个关联数组的数组。我试图从价格中删除逗号:
for ($i =1 ; $i<4; $i++) {
foreach ($array[$i]['product'] as $products) {
str_replace(',', '', $products ['price']);
}
}
答案 0 :(得分:1)
for ($i =1 ; $i<4; $i++) {
foreach ($array[$i]['product'] as $products) {
$products ['price'] = str_replace(',', '', $products ['price']);
}
}
您需要将值分配回数组。或者:
for ($i =1 ; $i<4; $i++) {
foreach ($array[$i]['product'] as $products) {
$array [$i]['product']['price'] = str_replace(',', '', $products ['price']);
}
}