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

What data type is the variable $age = 25; in PHP?

A). Integer

B). String

C). Boolean

D). Float

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 PHP operators is used for concatenation of strings?

A). .

B). +

C). &&

D). *

Which of the following statements is true about PHP comments?

A). Comments are ignored by the PHP interpreter

B). Comments can only be single-line

C). Comments must start with /* and end with */

D). Comments are displayed on the webpage

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 valid variable name in PHP?

A). $my_var

B). $my-var

C). $my var

D). my_var

Which of the following PHP functions is used to find the length of an array?

A). count()

B). length()

C). size()

D). sizeof()

What is the correct way to declare a variable in PHP?

A). $name = 'John';

B). name = 'John';

C). var name = 'John';

D). String name = 'John';

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];