0

Can you please tell what is wrong here, because i get an annoying message in my if statement:

Notice: Undefined offset: 1

The code:

$maxlvls[14] = array(0, 30, 25, 20, 15, 1, 20, 25, 30, 30, 30, 30, 30, 10, 20);

$lvle[14] = array(0, (int)$_GET['ratuszlvl'], (int)$_GET['koszarylvl'], (int)$_GET['stajnialvl'], (int)$_GET['warsztatlvl'], (int)$_GET['palaclvl'], (int)$_GET['kuznialvl'], (int)$_GET['ryneklvl'], (int)$_GET['tartaklvl'], (int)$_GET['cegielnialvl'], (int)$_GET['hutalvl'], (int)$_GET['zagrodalvl'], (int)$_GET['spichlerzlvl'], (int)$_GET['schoweklvl'], (int)$_GET['murlvl']);

if($lvle[1] <= $maxlvls[1] && $lvle[1] >= 0)
{
    echo "smth";
}
7
  • 1
    Where do you expect $lvle[1] to come from, if you only assigned a value to $lvle[14] …? Commented May 11, 2014 at 13:40
  • So it's not like in C++? :( Commented May 11, 2014 at 13:40
  • I'm really disapointed from the questions under this tag recently Commented May 11, 2014 at 13:41
  • @user3576397 does C++ allow you to set only 14th element in array, but to use its 1st element instead? Commented May 11, 2014 at 13:41
  • 1
    @user3576397 nope, arrays are dynamically sized. Commented May 11, 2014 at 13:41

1 Answer 1

4

Instead of

$maxlvls[14] =
$lvle[14] =  

Use just

$maxlvls = 
$lvle = 

You don't have to declare (actually you can't) array's length in php(I guess you are doing this). However,assigning like :

$maxlvls[14] = array(...);

Means that you are assigning an array to the element of array $maxlvls with key 14.

Sign up to request clarification or add additional context in comments.

1 Comment

So simple explanation... It works and you are right that i was trying to set an array length. I'm new in PHP - previously i was learning C++.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.