I have a variable $data in my controller. In which I am getting the following result
Array( [0] => 99 [1] => 100 [2] => 101 [3] => 102 [4] => 103)
Now I want to get the single entry one by one by using for loop. The main purpose of this loop is that I want to insert these values in my DB table.
if(Yii::$app->request->isAjax && Yii::$app->request->post())
{
$data = explode(',',$_POST['data']);
for($i=0; $i<=count($data); $i++)
{
print_r($data[$i]);
}
//print_r($data);
}
else{
echo 'no data';
}
exit();
When i Run this one, I am getting the error
500 Internal Server Error PHP Notice 'yii\base\ErrorException' with message 'Undefined offset: 5'
Stack Trace
Stack trace:
#0 E:\xampp\htdocs\inventory-
web\backend\controllers\OgpheaderController.php(170): yii\base\ErrorHandler-
>handleError(8, 'Undefined offse...',
'E:\\xampp\\htdocs...', 170, Array)
#1 [internal function]: backend\controllers\OgpheaderController-
>actionViewsetpdf('55')
#2 E:\xampp\htdocs\inventory-
web\vendor\yiisoft\yii2\base\InlineAction.php(57):
call_user_func_array(Array, Array)
#3 E:\xampp\htdocs\inventory-
web\vendor\yiisoft\yii2\base\Controller.php(156): yii\base\InlineAction-
>runWithParams(Array)
#4 E:\xampp\htdocs\inventory-web\vendor\yiisoft\yii2\base\Module.php(523):
yii\base\Controller->runAction('viewsetpdf', Array)
#5 E:\xampp\htdocs\inventory-
web\vendor\yiisoft\yii2\web\Application.php(102): yii\base\Module-
>runAction('ogpheader/views...', Array)
#6 E:\xampp\htdocs\inventory-
web\vendor\yiisoft\yii2\base\Application.php(380): yii\web\Application-
>handleRequest(Object(yii\web\Request))
#7 E:\xampp\htdocs\inventory-web\backend\web\index.php(17):
yii\base\Application->run()
#8 {main}</pre>
I have searched for this error solution but couldn't find the correct answer(s).
Any help would be highly appreciated.
$i<count($data)