$ary = [ "いちご" => 1, "バナナ" => 2 ]; foreach($ary as $key => $value){ if($key == "いちご"){ $ary["いちご"] = $value + 3; } } echo "<pre>"; var_dump($ary); echo "</pre>";
なるほど、これを応用する
$ary = [ "A商事" => 1200, "B商事" => 2000 ]; $name ="C商事"; $subtotal = 2000; foreach($ary as $key => $value){ if($key == $name){ $ary[$key] = $value + $subtotal; } else { $ary[$name] = $subtotal; } } echo "<pre>"; var_dump($ary); echo "</pre>";
OK, これをLaravelでやりたい。