Q:

Undefined offset in basic array script

What is Undefined offset error.
I am new in PHP world.
I write some code.But error appear like that.
Notice: Undefined offset: 5 in D:\xammp\htdocs\dashboard\ali.php on line 15
Student 5: 
Notice: Undefined offset: 6 in D:\xammp\htdocs\dashboard\ali.php on line 15
Student 6
here is code.

<?php

    $ali = array();
    $ali[1] = 1.3;
    $ali[2] = 3.2;
    $ali[3] = 3.4;
    $ali[4] = 4.3;

    for($i = 7; $i <= 150; $i++){
        $ali[$i] = mt_rand(20, 40) * 0.1; 
    }

    $x = 1;
    while($x < 7){
        echo "Student $x: " . $ali[$x] . "<br />";
        $x +=1;
    }

?>

A:

Yes, you are setting from 1 till 4, then skipping 5 and 6, then starting with 7:
$ali = array();
$ali[1] = 1.3;
$ali[2] = 3.2;
$ali[3] = 3.4;
$ali[4] = 4.3;
// 5 and 6 not defined, but started with 7 assignment for the next loop.

So add values for 5 and 6, or change it:
for($i = 5; $i <= 150; $i++){
    $ali[$i] = mt_rand(20, 40) * 0.1; 
}

