Functions Flashcards
1
Q
How do you call a function where the parameters are passed by reference?
A
function name($normal, &$passedByReference){ // code block }
2
Q
If you do not specify any parameters in a function definition, how do you gain access to them?
A
func_get_args()
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
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 }
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.