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

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 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 will be the result of the expression 10 % 3 in PHP?

A). 0

B). 1

C). 3

D). 10

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 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 'Hello' . ' World' in PHP?

A). 'Hello World'

B). 'Hello . World'

C). 'Hello + World'

D). 'Hello, World'

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

A). .

B). +

C). &&

D). *

What will be the output of the following PHP code?

<?php
$x = 10;
echo ++$x;
?>

A). 10

B). 11

C). 9

D). Error