所以我有一个由短语和单个单词组成的二维数组,称为$frags
'var_dump',如下所示:
array(4) {
[0]=> array(5) {
[0]=> string(3) "the" [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." }
}
当我var_dump($frags[0])
给我:
array(5) {
[0]=> string(3) "the" [1]=> string(4) "term" [2]=> string(4) "'AI'" [3]=> string(5) "still" [4]=> string(7) "manages" }
但是当我尝试打印时$frags[0][0]
,它给了我:
注意:未定义的偏移量:第 57 行 C:\wamp\www\jpsmythe\parser.php 中的 0
注意:未定义的偏移量:第 57 行 C:\wamp\www\jpsmythe\parser.php 中的 0
字符串(3)“的”
这是没有意义的。我觉得我已经尝试了所有方法,包括将 0 视为字符串,但它仍然没有看到它。帮助?
相关代码:
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]);
}