Answer & Solution
foreach loop to iterate over each element of the $colors array and print it. Therefore, the purpose of the code is to loop through an array and print each element.
foreach ($colors as $color) {
echo $color . "
";
}
?> | PHP | MYTAT">
foreach ($colors as $color) {
echo $color . "
";
}
?> | PHP | MYTAT">
<?php
$colors = array('Red', 'Green', 'Blue');
foreach ($colors as $color) {
echo $color . '
';
}
?>
foreach loop to iterate over each element of the $colors array and print it. Therefore, the purpose of the code is to loop through an array and print each element.
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 PHP functions is used to convert a string to uppercase?
A). strtoupper()
B). ucwords()
C). strtolower()
D). ucfirst()
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 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). !=
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 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 output of the following PHP code?<?php
$x = 10;
echo ++$x;
?>
A). 10
B). 11
C). 9
D). Error
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