J'ai un tableau 2-D, des phrases et des mots individuels, appelés $frags
, c'est `var_dump comme ceci:PHP: Undefined offset à 0, mais il est là (je pense)
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." }
}
quand je var_dump($frags[0])
il me donne:
array(5) {
[0]=> string(3) "the" [1]=> string(4) "term" [2]=> string(4) "'AI'" [3]=> string(5) "still" [4]=> string(7) "manages" }
Mais lorsque je tente d'imprimer $frags[0][0]
il me donne:
Notice: Undefined de fset: 0 C: \ wamp \ www \ jpsmythe \ parser.php sur la ligne 57
Indication: Undefined offset: 0 C: \ wamp \ www \ jpsmythe \ parser.php sur la ligne 57
chaîne (3) "le"
ce qui n'a aucun sens. J'ai l'impression d'avoir tout essayé, y compris de traiter le 0 comme une corde, mais il ne le voit toujours pas. Aidez-moi?
Le code correspondant:
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]);
}
Quelle version de PHP? – cdhowie
En effet, cela n'a pas de sens. Veuillez coller à nouveau le vidage en utilisant 'var_dump()' et le formatage du code de stackoverflow et collez le code réel et le message d'erreur réel. Doit être une faute de frappe ou quelque chose. – AndreKR
La version est 5.3.0. Je posterai la partie la plus pertinente du code; C'est une très petite partie d'un programme beaucoup plus vaste. – garbageman14