Answer & Solution
$my_var
is a valid variable name, while $my-var
and $my var
are not.
$my_var
is a valid variable name, while $my-var
and $my var
are not.
What will be the output of the following PHP code?<?php
$x = 5;
$y = 10;
echo 'The sum is: ' . ($x + $y);
?>
A). The sum is: 15
B). The sum is: 5 + 10
C). The sum is: $x + $y
D). The sum is: 510
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 functions is used to find the length of an array?
A). count()
B). length()
C). size()
D). sizeof()
What will be the output of the following PHP code?<?php
$x = 10;
echo ++$x;
?>
A). 10
B). 11
C). 9
D). Error
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
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
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 operators is used for concatenation of strings?
A). .
B). +
C). &&
D). *
Which of the following PHP functions is used to convert a string to uppercase?
A). strtoupper()
B). ucwords()
C). strtolower()
D). ucfirst()