As stated in the title, I encounter a strange problem for the following code.
for($i=0; $i < count($maindata) ; $i++){
$currentId = $maindata[$i]['SubmissionId'];
$output = array_filter($subdata, function ($value) use ($currentId)
{ return $subdata['ParentId'] == $currentId; });
echo 'total sub data '.count($output); //output 86
for($j=0; $j < count($output) ; $j++){
echo $output[$j]['SubmissionId']; //Undefined offset Error
}
}
As you can see, I loop through an array. Inside the loop I filter out another array to get the associate data.
And then I echo the count of the filter array and echo the data with another loop. The code was fine for first item and it show data but starting from the second item, it show
Notice: Undefined offset: 0 in myfile on line 79
inside the second loop but the count still showing correct answer also. line 79 is echo $output[$j]['SubmissionId']; //Undefined offset Error .
Please help me to figure out what is the problem. Thanks in advance.
if(isset($output[$j]['SubmissionId'])){echo $output[$j]['SubmissionId'];}. More you have to print$outputbefore second iteration and show us the data. May be some correction required