tooted=array(); $f=fopen("tooted2.txt", "r"); while($rida=fgets($f, 100)){ $m=explode(",", $rida); array_push($this->tooted, array($m[0], floatval($m[1]), 0)); } echo ($_SESSION["kogused"]); if(isSet($_SESSION["kogused"])){ $m=explode(",", $_SESSION["kogused"]); for($i=0; $itooted[$i][2]=intval($m[$i]); } } if(isSet($_REQUEST["lisa"])){ $this->tooted[intval($_REQUEST["lisa"])][2]++; } if(isSet($_REQUEST["eemalda"])){ if($this->tooted[intval($_REQUEST["eemalda"])][2]>0){ $this->tooted[intval($_REQUEST["eemalda"])][2]--; } } $abi=array(); foreach($this->tooted as $toode){ array_push($abi, $toode[2]); } $_SESSION["kogused"]=join(",", $abi); } function teave(){ return "Ostuandmete klass"; } function toodeteLoetelu(){ $t=""; $nr=0; foreach($this->tooted as $toode){ $t.="\n"; $nr++; } $t.="
".htmlspecialchars($toode[0])." $toode[1]$toode[2] + -
"; return $t; } } $korv=new Ostukorv(); echo $korv->toodeteLoetelu();