1

Whenever I see output it displays $iV is less than 10. but i want $iV to display the number instead of the name of variable what am i doing wrong here?

$iV = 7; 


if($iV > 10)
{ 

  $r = '$iV is greater than 10'; 
}

else
{

  $r = '$iV is less than 10';
}

echo "<p>$r</p>"

1 Answer 1

1

Use double quotes (") instead of single quotes ('). Variables are not escaped in single quoted strings.

Reference:

Note: Unlike the double-quoted and heredoc syntaxes, variables and escape sequences for special characters will not be expanded when they occur in single quoted strings.

Working code:

$iV = 7; 

if($iV > 10)
{ 
  $r = "$iV is greater than 10"; 
}
else
 {
  $r = "$iV is less than 10";
}

echo "<p>$r</p>" 
Sign up to request clarification or add additional context in comments.

Comments

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.