LB2745
LB2745

Reputation: 11

PHP: Display outputting variable

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>"

Upvotes: 1

Views: 32

Answers (1)

user1544337
user1544337

Reputation:

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>" 

Upvotes: 1

Related Questions