views:

357

answers:

11
+18  A: 

Running php -l (lint) on your code I get a

Parse error: syntax error, unexpected T_DOUBLE_ARROW

The T_DOUBLE_ARROW token is what PHP expects when assigning array values to array keys.

When comparing for Greater than or equal to the PHP Parser expects T_IS_GREATER_OR_EQUAL, meaning you have to use >= instead of =>.

See

Gordon
+1 and even when you are not familiar with all the tokens, `T_DOUBLE_ARROW` is a quite descriptive name. Sad that there are people who need to split their code into several lines in order to understand that. (It would be quite understandable if they got `unexpected T_PAAMAYIM_NEKUDOTAYIM` though...)
nikic
A: 

Add one more bracket around the conditions in if....

if ( ($varp80000) && ($varp100000) && ($varp120000) && ($varp140000) && ($varp160000) && ($varp180000) && ($varp200000) && ($varp220000) && ($varp240000) && ($varp260000) && ($varp280000) && ($varp=300000) ) { $o13 = "1"; }

echo
+1  A: 

You probably want to change ($varp=300000) to ($varp==300000) and it might help to enclose the full if-statement inside (), like this

if($varp80000 && $varp100000 && $varp120000 && $varp140000 && $varp160000 && $varp180000 && $varp200000 && $varp220000 && $varp240000 && $varp260000 && $varp280000 && $varp==300000) { $o13 = "1"; }

On another note, where to these strange $varp#### variables come from?

Htbaa
+1  A: 

Not sure whether the code you've posted has gotten messed up somehow, but it looks like you're missing "==" in some of the if conditions. Also, as Skilldrick pointed out, the whole if condition should be in parentheses

Gary
+2  A: 

This is more readable and compact way to do the same:

$ranges = range(300000, 80000, -20000);

$index = 1;

$varp = 220001;

foreach ($ranges as $i => $range) {
    if ($varp >= $range) {
        $index = 13 - $i;
        break;
    }
}

${'o' . $index} = 1;

Anyway - I think you're doing something wrong with using variable name of result.

zerkms
A: 

Edit - Nevermind. Question has changed entirely since I wrote this up.


1 - $varp=300000 should probably be $varp300000

2 - You need another pair of brackets around the entirety of the if-statement:

if ($varp80000) && ($varp100000) && ($varp120000)
   && ($varp140000) && ($varp160000) && ($varp180000)
   && ($varp200000) && ($varp220000) && ($varp240000)
   && ($varp260000) && ($varp280000) && ($varp300000)

becomes

if ( ($varp80000) && ($varp100000) && ($varp120000)
     && ($varp140000) && ($varp160000) && ($varp180000)
     && ($varp200000) && ($varp220000) && ($varp240000)
     && ($varp260000) && ($varp280000) && ($varp300000) )

3 - Your variables $varp# may actually not set anywhere. If you're expecting an array, you probably want something like:

while ($row = mysql_fetch_array($result)) {
   $varp = unserialise($row['ustk_retail']);
   if (    ($varp[80000]) && ($varp[100000]) && ($varp[120000])
        && ($varp[140000]) && ($varp[160000]) && ($varp[180000])
        && ($varp[200000]) && ($varp[220000]) && ($varp[240000]) 
        && ($varp[260000]) && ($varp[280000]) && ($varp[300000]) )
   {
       $o13 = "1";
   }
}
pinkgothic
+9  A: 

Greater than or equal to is >= sign, not =>

Update:
You are right. It's small but hard to find mistake.
It took me to split whole line into pieces to see where the problem is:

<?php
if 
(
$varp
=>
80000
)

So, it says parse error on line 5 and I had to doublecheck this operator.
Of course, at first I separated the problem line from the rest of the code to be certain.

Col. Shrapnel
Actually, if you know what the T_DOUBLE_ARROW mentioned in the error message refers to, the error is obvious and easy to find. See the linked list of parser tokens in my answer.
Gordon
+3  A: 

You have an expression error.

$varp=>220000 // is not a valid php expression

=> operator is used to assign values in arrays like:

$x = array( 'foo' => 'bar');

>= is the comparation assigment greater than or equal
Elzo Valugi
+2  A: 

The answer has already been given but thought this was neat enough to share:

PHP accepts boolean expressions in it's switch statement.

switch(TRUE) {
    case $range <= 10:  echo "range below or equal to 10"; break;
    case $range <= 20:  echo "range above 10 below or equal to 20"; break;
    case $range <= 30:  echo "range above 20 below or equal to 30"; break;
    default: echo "high range";
}

In my opinion this generates the cleanest most readable code.

Les
You probably mean `switch(true) { /* rest of your code goes here */ }`, though, right?
pinkgothic
fixed $range to TRUE
Gordon
ah right tnx, wouldve been a nice bug for later if range ever hits "0" :)
Les
wow, I developed in PHP for years but i never saw this use of the switch statement, it's coool ! thx ;)
Cesar
+2  A: 

You have made a mistake in the if conditions. The greater than Equal to sign is >= and not =>.

Joy
A: 

"Greater than or equal to is >= NOT =>. You use => for arrays for keys/values.

ggfan