What function is used to create an array in PHP?
A
array() B
makearray() C
createArray() D
new array()
Analysis & Theory
The `array()` function is used to create arrays in PHP.
What is the correct syntax to create an empty array?
A
$arr = (); B
$arr = array(); C
$arr = array[]; D
$arr = empty();
Analysis & Theory
The correct syntax is `$arr = array();` to create an empty array.
Which of the following creates an Indexed Array?
A
$colors = array('red', 'green', 'blue'); B
$colors = array('color1' => 'red', 'color2' => 'green'); C
$colors = array(); D
$colors = empty;
Analysis & Theory
An Indexed Array is created by listing values without keys.
What is the correct way to create an Associative Array?
A
$person = array('name' => 'John', 'age' => 25); B
$person = array('John', 25); C
$person = ['John', 25]; D
$person = array('John' => name, 25 => age);
Analysis & Theory
Associative Arrays use key-value pairs like `'name' => 'John'`.
What does the following code create?
```
<?php
$arr = array(1, 2, 3);
?>
```
A
Associative Array B
Indexed Array C
Empty Array D
Multidimensional Array
Analysis & Theory
It creates an Indexed Array with values `1, 2, 3`.
Is it possible to create an array using square brackets `[]` in PHP?
A
No B
Yes, from PHP 5.4 onwards C
Yes, in PHP 4 D
Only for empty arrays
Analysis & Theory
PHP allows array creation using `[]` syntax starting from version 5.4.
What is the output?
```
<?php
$colors = array('red', 'green', 'blue');
echo $colors[1];
?>
```
A
red B
green C
blue D
Error
Analysis & Theory
Index 1 corresponds to `'green'` in the array.
Which of the following creates a Multidimensional Array?
A
$arr = array(array(1, 2), array(3, 4)); B
$arr = array(1, 2, 3, 4); C
$arr = array('name' => 'John', 'age' => 25); D
$arr = array();
Analysis & Theory
A Multidimensional Array is an array that contains one or more arrays as elements.
What is the output?
```
<?php
$data = array();
echo count($data);
?>
```
A
1 B
0 C
Error D
array
Analysis & Theory
`count()` returns `0` because the array is empty.
Can an array in PHP store different data types together?
A
No B
Yes C
Only strings D
Only integers
Analysis & Theory
PHP arrays can store mixed data types like integers, strings, floats, and even other arrays.