Question

I have this simple loop:

for($i=$_POST['position'];$i<count($myFiles);$i++)
{
    $withoutNumber = explode("_",$myFiles[$i]);
    $noNr = unset($withoutNumber[0]);
}

My code editor is Aptana, and the problem is that when I write this code I get the unset keyword underlined like is an syntax error and I have no idea why that happens. I can not test the code right now (this loop is part of a complex code) so I don't really know if the problem is real or not. What could the problem could be?

Was it helpful?

Solution

You portion of code, if you try to execute it, gives :

Parse error: syntax error, unexpected T_UNSET

Which means the problem is in your code, and not with your editor ;-)


Considering unset doesn't return anything, you should have :

for($i=$_POST['position'];$i<count($myFiles);$i++)
{
    $withoutNumber = explode("_",$myFiles[$i]);
    unset($withoutNumber[0]);
}

Which is working much better : no Parse Error anymore.

And I suppose that Aptana "knows" that this language construct shouldn't return anything -- which is why it indicates there is an error.

OTHER TIPS

unset is a language construct and not a normal function, and thus can not be used to set a variable. See unset():

Note: Because this is a language construct and not a function ...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top