0

I am using this code but getting PHP Syntax Check: Parse error: syntax error, unexpected 'if' (T_IF).

$string = "<span class=\"titlec\">" . $myname . if (strval(get_field('br_featured', $prev_id)) > 0) {echo "<span title=\"Listing\" class=\"mond\"></span>";} . "</span>"

Not sure what the solution would be here. Any help would be much appreciated.

JoaMika
  • 1,727
  • 6
  • 32
  • 61
  • You are using an `if` within an expression. It does not work like that. – yivi Feb 06 '21 at 10:45
  • Either move the `if` block outside the assignment statement, and there assign a string to a variable than then you use to assign to `$string`, or use a ternary operator. – yivi Feb 06 '21 at 10:47
  • You can use the ternary operator : `$string = "". $myname . (((string) get_field('br_featured', $prev_id) > 0) ? "" : "");` Also, you can replace `strval()` with a string cast. – COil Feb 06 '21 at 10:50

0 Answers0