php - Making array after explode -
i want create array input string. before code, i've tried explode, array remains length 1. each string i've tried still 1 in array[0]. here's code far:
public function word() { $kata = array($this->kal->gethasil()); if (!empty($kata)) { $n = count($kata) ($i = 0; $i < $n; $i++) { $imin = $i; ($j = $i; $j < $n; $j++) { if ($kata[$j] < $kata[$imin]) { $imin = $j; } } $temp = $kata[$i]; $kata[$i] = $kata[$imin]; $kata[$imin] = $temp; } ($i = 0; $i < $n; $i++) { echo "$kata[$i] "; } } } public function tokenize() { $temp = $this->kal->gethasil(); $token = explode(" ", $temp); return $token; } $hasil = $pp->tokenize(); ($i = 0; $i < sizeof($hasil); $i++) { $st = new stemming(); $hasil[$i] = $pp->singkatan($hasil[$i]); $hasil[$i] = $st->stem($hasil[$i]); $hasil[$i] = $pp->stopword($hasil[$i]); //echo "$hasil[$i] "; $hb = new hitungbobot($hasil[$i]); $hb->word(); }
how fix this?
you can use globar var, see code:
public function word(){ $kata = array($this->kal->gethasil()); global $output; if(!empty($kata)){ $ar= count($kata) $output += $ar; } public function tokenize() { $temp = $this->kal->gethasil(); $token = explode(" ",$temp); return $token; } $output = 0; $hasil = $pp->tokenize(); for($i=0; $i<sizeof($hasil); $i++) { $st = new stemming(); $hasil[$i] = $pp->singkatan($hasil[$i]); $hasil[$i] = $st->stem($hasil[$i]); $hasil[$i] = $pp->stopword($hasil[$i]); //echo "$hasil[$i] "; $hb = new hitungbobot($hasil[$i]); $hb->word(); } echo $output;
Comments
Post a Comment