Arrays Flashcards

1
Q

How do you add an element called Apple to the end of an array named ‘$fruits’.

A

array_push($fruits, ‘Apple’);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Using variable $lastFruit, how do you remove the last element from an array named ‘$fruits’ and return it?

A

$lastFruit = array_pop($fruits);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Using variable $firstFruit, how do you remove the first element from an array named ‘$fruits’ and return it?

A

$firstFruit = array_shift($fruits);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do you add Mango and Pineapple to the beginning of an array named ‘$fruits’

A

array_unshift($fruits, ‘Mango’, ‘Pineapple’);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Using variable $combinedArray, how do you combine two arrays, ‘$array1’ and ‘$array2’ into a single array?

A

$combinedArray = array_merge($array1, $array2);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Using variable $reversedArray, how would you reverse the following array:

$fruits = [“Apple”, “Orange”, “Banana”, “Pear”];

A

$reversedArray = array_reverse($fruits);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Create an associate array named $capitals. It should contain the capital cities of “UK”, “France”, “Spain”, and “Wales”.

A

$capitals = [
“UK” => “London”,
“France” => “Paris”,
“Spain” => “Madrid”,
“Wales” => “Cardiff”
];

How well did you know this?
1
Not at all
2
3
4
5
Perfectly