PHP Flashcards

1
Q

What array holds the values of submitted form parameters?

A

$_POST

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

How to get the URL of the current page (without protocol or hostname).

A

$_SERVER[PHP_SELF]
eg:
/users/enter.php

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

What does $_SERVER[PHP_SELF] return

A

The URL of the current page (without protocol or hostname).
eg:
/users/enter.php

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

What are the start and end tags of PHP. What are they for?

A

< ? php and ? >

The PHP engine ignores anything outside of those tags.. You can leave off the end tag at the end of a PHP file.

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

Can a PHP program have multiple start and end tag pairs?

A

Yes

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

Is there only one start php tag?

A

No, you can also use < ? but support depends on the engine.

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

Are php keywords case-sensitive?

A

No, language keywords and function names are not case-sensitive. Variable names ARE! Best practice is to assume everything is.

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

What is the single-line commenting style?

A

Either // or #

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

Does php offer native Unicode support?

A

No, a string in php is a sequence of bytes and hence only natively supports a 256-character set.

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

Quotes used to surround a string are technically called…

A

delimiters

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

To concatenate two strings?

A

. (period) operator

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

What is the exponentiation operator?

A

**

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

What is the modulus division operator?

A

%

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

Can you use a dash in variable names in PHP?

A

No, only underscore.

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

How do you interpolate variables into a string?

A

“Hello, ${name}”

Use double-quotes. Braces aren’t necessary for this simple example, but prefer them always.

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

What is truthy / falsy in PHP?

A

This is called an expression’s ‘truth value.’
There are only seven specific results that evaluate to false.
All integers and floating-point values (except 0 and 0.0) are true.
All strings (except empty string “” and “0”) are true.
The special constants false and null also evaluate to false.
An empty array is false.
(There are also empty SimpleXML objects and -0 and -0.0, but let’s keep it simple…)

17
Q

How to avoid accidentally using = (assignment) instead of == (equality)?

A

Always put the variable name on the right and assignment will cause a parse error:
if (12 = $myvar) { … }

18
Q

What is the spaceship operator?

A

<=> works like strcmp(), but for any data type.
Evaluates to a negative number when its lefthand operand is less than the righthand operand, a positive number when the righthand operand is bigger, and 0 when they are equal.

19
Q

Each element of an array has a … and a …

A

key and a value.

20
Q

An array key can be…

A

…any unique scalar value.

21
Q

Syntax to create an array

A

$nums = array(1, 2, 3, 4);
or
$veggies = array(‘corn’ => ‘yellow’, ‘beet’ => ‘red’);

22
Q

Shortcut for array() construct…

A

$arr = [0 => ‘zero’, 1 => ‘one’];

23
Q

How to append to an array?

A

Empty brackets append to an array. If the array doesn’t exist yet, element is added at key 0.

// set $arr[0]
$arr[] = 'breakfast';
// set $arr[1]
$arr[] = 'lunch';
24
Q

How to get the number of elements in an array?

A
The count() function:
count($arr);
25
Q

What function checks for existence of a certain key in an array?

A

array_key_exists(‘key’) returns a boolean

26
Q

What function checks for existence of a certain value in an array?

A

in_array(value, $arr) returns a boolean (is case sensitive)

27
Q

What function finds the given value in an array?

A

array_search(value, $arr) returns the key of found value.

28
Q

To remove an element from an array?

A

Use:

unset($arr[key]);

29
Q

Easiest way to convert an array to string?

A

implode(‘, ‘, $arr);

30
Q

Counterpart to the ‘implode’ function?

A

explode() breaks a string apart into an array given a delimiter.

31
Q

Difference between iterating over an array using for vs foreach

A

foreach visits array elements in the order in which they were created - which isn’t necessarily sequentially by the keys.