Chapter 6 - PHP Arrays Flashcards

1
Q

What does this output?

A

Array ( [0] => Copier [1] => Inkjet [2] => Laser [3] => Photo )

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

What is an associative array?

A

Using them, you can reference the items in an array by name rather than by number.

Example:

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

What is the difference between a numeric and an associative array?

A

A numeric array can be indexed numerically using numbers or numeric variables. An associative array uses alphanumeric identifiers to index elements.

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

What is the main benefit of the array keyword?

A

The main benefit of the array keyword is that it enables you to assign several values at a time to an array without repeating the array name.

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

What is the difference between foreach and each?

A

Both the each function and the foreach … as loop construct return elements from an array; both start at the beginning and increment a pointer to make sure the next element is returned each time; and both return FALSE when the end of the array is reached. The difference is that the each function returns just a single element, so it is usually wrapped in a loop. The foreach … as construct is already a loop, executing repeatedly until the array is exhausted or you explicitly break out of the loop.

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

How can you create a multidimensional array?

A

To create a multidimensional array, you need to assign additional arrays to elements of the main array.

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

How can you determine the number of elements in an array?

A

You can use the count function to count the number of elements in an array.

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

What is the purpose of the explode function?

A

The purpose of the explode function is to extract sections from a string that are separated by an identifier, such as extracting words separated by spaces within a sentence.

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

How can you set PHP’s internal pointer into an array back to the first element of the array?

A

To reset PHP’s internal pointer into an array back to the first element, call the reset function.

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

What is the opposite of the explode function?

A

The implode function

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