Q
Which of the following is a correct way to declare an array in PHP?

Answer & Solution

Answer: Option A
Solution:
Arrays in PHP are declared using the array() construct. Therefore, the correct way to declare an array $colors with values 'Red', 'Green', and 'Blue' is $colors = array('Red', 'Green', 'Blue');. The other options are incorrect syntax for declaring arrays in PHP.
Related Questions on Average

Which of the following PHP functions is used to convert a string to uppercase?

A). strtoupper()

B). ucwords()

C). strtolower()

D). ucfirst()

What does the following PHP code output?

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

A). 30

B). 1020

C). Error

D). 102

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

What will be the result of the expression 10 % 3 in PHP?

A). 0

B). 1

C). 3

D). 10

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

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;
$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). *