0

I hope this question hasn't been asked yet.

Time to time I get into the same problem while I'm coding, which is when I'm using two or more && logical operators like this:

if ($sCategory['sub_category_name'] == $subCat && $action == 'edit') {
    //Do stuff here
}

I get the error:

PHP Parse error: syntax error, unexpected '$action' (T_VARIABLE)

As reading some of other topics, I saw that sometimes there are hidden characters which cause the problem, but I did not find any other solution to mine. I'm using Sublime Text 3 on an iMac.

Thanks in advance

Narc0t1CYM
  • 499
  • 6
  • 25

1 Answers1

1

Please try this:

According to me, the array value is creating issue, so take this array value in another variable, just like this:

$cat_val = $sCategory['sub_category_name'];
if (($cat_val == $subCat) && ($action == "edit")) {
    //Do stuff here
}

Please try it once.

Hope, it may be helpful to you.

Prateek Verma
  • 869
  • 1
  • 6
  • 9
  • That might be a possible solution, I'll check it – Narc0t1CYM Feb 16 '17 at 11:35
  • I checked it and it works like that. Is there any restriction in php that it == logical operator can't compare more than x variables/array values? – Narc0t1CYM Feb 16 '17 at 11:37
  • Ok, it depends on the server to server versions. In localhost, it will not create problem in most of the cases, but on many live servers it creates issue. – Prateek Verma Feb 16 '17 at 11:38