Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Pessoal, Tô com problema nesse código: "Warning: Undefined offset: 3 and Undefined offset: 5, nesta linha (36): $cd [$ i] [$ id] [$ j]. =" $ Row ";
Já tentei com isset mas não dei jeito. Sei que este erro pode ocorrer com array vazio mas o array tem dados.
O call stack do PHP tá apontando pro $j :
$j =G:\XAMPP\htdocs\guardiao\inventario\Stackoverflow_1.php:36:int 3
$match = G:\XAMPP\htdocs\guardiao\inventario\Stackoverflow_1.php:36: array (size=0) - empty
Alguém consegue me ajudar?
}elseif(isset($id)){ // ignore all file header content
If (($row_previous == true)and ($row_ob !== true)){
++$j; //increment its index to insert variable value created for the additional lines
$row="(Ob) ". (trim($row)); //create pre value variable
$row_ob=true;
$cd[$i][$id][$j].="$row "; // concatenate to last element to new -linha (36)
}else{
$cd[$i][$id][$j].=" $row"; // concatenate to last element
}
}Olá Guilherme, eu executei var_dump em todos os array e, agora, descobri que o array vazio é o $match[1].
Saberia me ajudar a contornar o erro?
O array tá cheio mas quando chega no final do arquivo (arquivo txt), ele fica com valor 0 - array (size=0) empty
Esse é o código anterior ao que citei antes:
}elseif(preg_match('/^(\(..\)\s.*)/',$row,$match)){ // capture Cd data
++$j; // this is a new innerarray element, increment its index
$cd[$i][$id][$j]=$match[1]; // push element into array
//$concat=(strpos($match[1],'(Co)')!==0?true:false);
If (substr($row, 0, 5) == '(Co) ') {
$row_previous=true;
}Então...
Se o array chega vazio é porque você não está passando ele...
Posta o código antes deste momento, quando o $match é criado para vermos onde você ta perdendo ele.
Este é o código Guilherme,
while(!feof($file)){
$row=trim(fgets($file,1024));
if(preg_match('/^\(Cd\)\s(.+)/',$row,$match)){ // capture Cd numbers
++$i; // increment outer_index
$j=-1; // reset inner_index
$id=$match[1]; // store cd value
//$concat=true;
$row_previous=false;
$row_ob=false;
}elseif(preg_match('/^(\(..\)\s.*)/',$row,$match)){ // capture Cd data
//if(isset($match)?$j:$j);
++$j; // this is a new innerarray element, increment its index
$cd[$i][$id][$j]=$match[1]; // push element into array
If (substr($row, 0, 5) == '(Co) ') {
$row_previous=true;
}
}elseif(isset($id)){
If (($row_previous == true)&& ($row_ob !== true)){
++$j; //increment its index to insert variable value created for the additional lines
$row="(Ob) ". (trim($row)); //create pre value variable
$row_ob=true;
$cd[$i][$id][$j].="$row "; // concatenate to last element to new
}else{
$cd[$i][$id][$j].=" $row"; // concatenate to last element
$row_previous=false;
$row_ob=false;
}
}
}
no seu array você está pedindo a posição 3 e 5 e elas não existem.
Esse erro aparece quando alguma posição inexistente do array é requisitada.
Exemplo que dará esse mesmo erro: