爆炸后制作数组

Making array after explode

我想从输入字符串创建一个数组。在这段代码之前,我试过爆炸,但数组的长度仍然为 1。我试过的每个字符串仍然是数组 [0] 中的一个。到目前为止,这是我的代码:

public function word()
{
    $kata = array($this->kal->getHasil());
    if (!empty($kata)) {

        $n = count($kata)

        for ($i = 0; $i < $n; $i++) {
            $imin = $i;
            for ($j = $i; $j < $n; $j++) {
                if ($kata[$j] < $kata[$imin]) {
                    $imin = $j;
                }
            }
            $temp = $kata[$i];
            $kata[$i] = $kata[$imin];
            $kata[$imin] = $temp;
        }

        for ($i = 0; $i < $n; $i++) {
            echo "$kata[$i] ";
        }
    }
}

public function tokenize()
{
    $temp = $this->kal->getHasil();
    $token = explode(" ", $temp);
    return $token;
}

$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();
}

我该如何解决这个问题?

可以使用globar var,见代码:

    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;