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 does the following PHP code output?

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

A). 30

B). 1020

C). Error

D). 102

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

A). $my_var

B). $my-var

C). $my var

D). my_var

What is the value of $x after the following PHP code is executed?

<?php
$x = 5;
$x += 3;
echo $x;
?>

A). 5

B). 8

C). 15

D). 3

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;

What is the purpose of the following PHP function?

strlen('Hello')

A). Returns the length of a string

B). Converts a string to lowercase

C). Checks if a string contains a substring

D). Returns the first occurrence of a substring in a string

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

What will be the result of the expression 'Hello' . ' World' in PHP?

A). 'Hello World'

B). 'Hello . World'

C). 'Hello + World'

D). 'Hello, World'

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

A). .

B). +

C). &&

D). *