views:

70

answers:

2

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 do you think about this,what the problem could be? thanks

+1  A: 

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.

Pascal MARTIN
that's absolutely right :D i admit that this is a stupid question :) i focused so much on that underlined unset that i forgot about that variable assignment :) thanks guys
kmunky
You're welcome :-) (boah, not a problem ^^ at least you'll have learnt something ;-) )
Pascal MARTIN
+1  A: 

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 ...

Pekka
The note says that you can't do something like `$fn='unset'; $fn($v);`
VolkerK
I quoted this to underline the fact that it is not a regular function. I'll remove the misleading part.
Pekka