Functions Flashcards

1
Q

How do you call a function where the parameters are passed by reference?

A
function name($normal, &$passedByReference){
    // code block
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

If you do not specify any parameters in a function definition, how do you gain access to them?

A

func_get_args()

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

How do you define a function with a variable number of parameters?

A
function nameOfYourFunction(){
    // code block;
}

Note that the parameter block is empty

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

How do you access a global variable inside a function?

A

Use ‘global’:

function nameOfFunction(){
    global $thisIsGlobal;
}

OR, pass it in as a paramter:

function nameOfFunction($thisIsGlobal){
    // code block
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How can you access all global variables?

A

$GLOBALS - this is an associative array of all global variables created anywhere in your program. You should do not directly manipulate $GLOBALS.

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