Define Variable Flashcards

1
Q

What is a variable in PHP?

A

A variable in PHP is a container for storing data values

Variables are represented by a dollar sign followed by the name of the variable.

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

How is a variable represented in PHP?

A

Variables are represented by a dollar sign followed by the name of the variable

Example: $username = “admin”.

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

What does the scope of a variable refer to?

A

The context within which it is defined and accessible.

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

What is Local Scope?

A

Variables defined within a function are local to that function and cannot be accessed outside of it

Example: function myFunction() { $localVar = “I am local”; }

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

What is Global Scope?

A

Variables defined outside of any function are global and can be accessed anywhere in the script

Example: $globalVar = “I am global”;

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

Fill in the blank: A _______ variable retains its value even after the function has finished executing.

A

static

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

What is the behavior of a static variable in PHP?

A

A static variable retains its value even after the function has finished executing

Example: function myFunction() { static $count = 0; $count++; echo $count; }

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

True or False: A local variable can be accessed outside its defining function.

A

False

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

True or False: A global variable can be accessed anywhere in the script.

A

True

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