PHP: 0, Ofset Tanımsız, ama (sanırım) var

0 Cevap php

Yani $frags denilen öbekleri ve tek tek sözcüklerin bir 2-D dizi, var, o `var_dump ait gibi pek ettik:

array(4) { 
[0]=> array(5) { 
    [0]=> string (3) "" [1]=> string(4) "term" [2]=> string(4) "'AI'" [3]=> string(5) "still" [4]=> string(7) "manages" } 
[1]=> array(2) { 
    [0]=> string(2) "to" [1]=> string(5) "creep" } 
[2]=> array(3) { 
    [0]=> string(4) "into" [1]=> string(2) "my" [2]=> string(6) "speech" } 
[3]=> array(2) { 
    [0]=> string(2) "or" [1]=> string(8) "writing." } 
}  

I var_dump($frags[0]) bana verdiğinde:

array(5) { 
    [0]=> string (3) "" [1]=> string(4) "term" [2]=> string(4) "'AI'" [3]=> string(5) "still" [4]=> string(7) "manages" } 

Ben yazdırmaya çalıştığınızda ancak $frags[0][0] bana verir:

Notice: Undefined offset: C 0: \ wamp \ www \ jpsmythe \ Parser.php hat 57 üzerinde

Notice: Undefined offset: C 0: \ wamp \ www \ jpsmythe \ Parser.php hat 57 üzerinde

string (3) ""

mantıklı değil ki. Ben bir dize gibi 0 tedavi dahil her şeyi denedim, ama yine de onu görmeye değil gibi hissediyorum. Yardım?

İlgili kod:

private function clause($frags) {
   // set the parser through the control hub
    $controller = Controller::getInstance();
    $parser = $controller->parser;
    $parser->init();

   // take the $frags array from elsewhere in the program
   // this $frags is actually punctuation-separated fragments of a sentence, not the  same as the $frags array with which I'm having problems now   
    $i = 0;
    $clauses = array();
   //run through the punctuated $frags array
    while ($i < count($frags)) {
        $pos = array();
        $num = 0;
        $p = 0;
// separated each punc'ed fragment into smaller fragments separated by stopwords        
        while ($p < count($frags[$i])) {
            if (array_key_exists($frags[$i][$p], $parser->stopwords)) {
                $pos[] = $p;
                $clauses[$num] = array();
                $num ++;
            }
            $p ++;
        }
        $pos[] = count($frags[$i]);

        $num = 0;
        $j = 0;
        if (count($pos) > 0) {
            while ($j < count($pos)) {
                $stop = FALSE;
                $k = $pos[$j]-1;
                while ($k >= 0 && !$stop) {
                    if (array_key_exists($frags[$i][$k], $parser->stopwords))
                        $stop = TRUE;
                    $clauses[$num][] = $frags[$i][$k];
                    $k --;
                }

                $clauses[$num] = array_reverse($clauses[$num]);
                $num ++;
                $j ++;
            }

           //send the array of stopped fragments to the parser
            $parser->parse($clauses);
            //$controller->setResponse($clauses);
        }
        $i ++;
    }
}

function parse($frags) {
    $i = 0;

    // more code here, commented out for the time being
    // below, send response to control hub for output
    $controller = Controller::getInstance();
    $controller->setResponse($frags[$i][0]);
}

0 Cevap