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

6
  • have you defined action variable ?? Commented Feb 16, 2017 at 11:12
  • have you tried this stackoverflow.com/questions/1464919/… Commented Feb 16, 2017 at 11:14
  • See the previous line ... if there is any error . Commented Feb 16, 2017 at 11:18
  • can you fetch the $sCategory['sub_category_name '] and $subcat and $action do you get the value? Commented Feb 16, 2017 at 11:19
  • post you whole script here Commented Feb 16, 2017 at 11:21

1 Answer 1

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.

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

3 Comments

That might be a possible solution, I'll check it
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?
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.

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.