Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP undefined offset from list()

Tags:

php

list(,,,,,,,,,$user, $pass) = explode("\t", $line);
if(trim($user) == $_POST['username'] && trim($pass) == $_POST['password'] )

The message undefined offset 10 , The message undefined offset 9 . the 9 and the 10 is the $user and $pass. How do i fix the error? and does undefined offset means its not being declared or something? and theres alot of ,,,,,,,, is because theres value but i dont need it for this php

like image 244
user3649899 Avatar asked Jun 25 '14 06:06

user3649899


1 Answers

undefined offset in this context means that you are expecting more parameters in your call to list than are in the array on the right hand of the equation.

You are expecting an array with a length of 11 but explode("\t", $line) is returning an array of less than 11 values.

You either need to ensure you have the right amount of tab separated values in $line or pad the output of explode using array_pad.

Below is an example of using array_pad to make sure the array has a length of 11:

list(,,,,,,,,,$user, $pass) = array_pad(explode("\t", $line), 11, null);

If $line did not contain enough tab separated values then $user and $pass would take the value null.

like image 64
Mitch Satchwell Avatar answered Oct 08 '22 04:10

Mitch Satchwell