echo "Hello, $name!";
?> | PHP | MYTAT"> echo "Hello, $name!";
?> | PHP | MYTAT">
Q
What will be the output of the following PHP code?

<?php
$name = 'John';
echo 'Hello, $name!';
?>

Answer & Solution

Answer: Option A
Solution:
In PHP, double quotes (') allow variable interpolation, meaning that variables within the string will be replaced with their values. Therefore, the output of the code will be Hello, John!, as the variable $name will be replaced with its value 'John' when the string is echoed.
Related Questions on Average

Which of the following PHP operators is used for concatenation of strings?

A). .

B). +

C). &&

D). *

What will be the output of the following PHP code?

<?php
$x = 10;
$y = 5;
echo $x + $y;
?>

A). 15

B). 5

C). 10

D). Error

Which of the following is a correct way to increment the value of a variable $count by 1 in PHP?

A). $count++;

B). $count += 1;

C). $count = $count + 1;

D). $count =+ 1;

Which of the following is a correct way to assign a floating-point number to a variable in PHP?

A). $price = 10.99;

B). $price = '10.99';

C). $price = '10.99';

D). $price = 10;

Which of the following PHP functions is used to convert a string to uppercase?

A). strtoupper()

B). ucwords()

C). strtolower()

D). ucfirst()

What will be the result of the expression 10 % 3 in PHP?

A). 0

B). 1

C). 3

D). 10

Which of the following is a valid variable name in PHP?

A). $my_var

B). $my-var

C). $my var

D). my_var

Which of the following is a correct way to declare an array in PHP?

A). $colors = array('Red', 'Green', 'Blue');

B). $colors = 'Red, Green, Blue';

C). $colors = {'Red', 'Green', 'Blue'};

D). $colors = [Red, Green, Blue];

Which of the following PHP operators is used to compare whether two values are equal and of the same data type?

A). ===

B). ==

C). =

D). !=

What will be the output of the following PHP code?

<?php
$x = 10;
echo ++$x;
?>

A). 10

B). 11

C). 9

D). Error