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 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 find the length of an array?

A). count()

B). length()

C). size()

D). sizeof()

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

A). .

B). +

C). &&

D). *

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

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 functions is used to convert a string to uppercase?

A). strtoupper()

B). ucwords()

C). strtolower()

D). ucfirst()

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 value of the variable $result after executing the following PHP code?

<?php
$x = 5;
$result = ($x > 10) ? 'Yes' : 'No';
?>

A). Yes

B). No

C). True

D). False

What will be the output of the following PHP code?

<?php
$x = 5;
echo $x--;
echo $x;
?>

A). 5 4

B). 5 5

C). 4 4

D). 4 5

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