Results: 1580
Notes
  • Newest first
  • Oldest first
  • Newest first(All)
  • Oldest first(All)
➤ The scope of a variable is the part of the script in which the variable can be referenced or used. • A variable declared outside a function has a
global scope
. • A variable declared within a function has a
local scope
, and can only be accessed within that function. For instance:
// global scope
$number = 10;
function print_num() { 
	echo "the number is: $number ";
}
print_num(); // outputs:  Undefined variable $number
// the $number variable has a global scope, and is not accessible within the print_num() function


function task() {
  $name = "Mads"; // local scope
  echo "Variable name inside function is: $name";
  // outputs:  Variable name inside function is: Mads
}
task();
// using $name outside the function will generate an error
echo "Variable name outside function is: $name";
// Undefined variable $name
by Levani Makhareishvili
2 years ago
0
PHP
variables
1
➤ Normally, when a function is completed/executed, all of its variables are deleted. However, sometimes we want a local variable NOT to be deleted. We need it for a further job. • To do this, use the
static
keyword when you first declare the variable: For instance:
// function with static variable
function get_num1() {
  static $number1 = 0;
  echo $number1++." ";
}
get_num1();
get_num1();
get_num1(); echo "\n";
// outputs:   0 1 2


// function without static variable
function get_num2() {
	$number2 = 0;
	echo $number2++." ";
}
get_num2();
get_num2();
get_num2();
// outputs:   0 0 0
by Levani Makhareishvili
2 years ago
0
PHP
static
variables
1
else-if example for fun CODE
Don't create variables with Georgian alphabet. The following example is just for fun!
$სწავლა_გვინდა = true;
$ვაბარებთ_უნივერსიტეტში = true;
$სწავლა_ძვირია = true;
$მუშაობა_გვინდა = false;

if ($სწავლა_გვინდა) {
	if ($ვაბარებთ_უნივერსიტეტში) {
		if ($სწავლა_ძვირია) {
			echo "\nუნივერსიტეტი ძვირია, ვიწყებთ სწავლას applications.ge-ს კურსზე!";
		} else {
			echo "\nვსწავლობთ უნივერსიტეტში!";
		}
	} else {
		echo "\nვიწყებთ სწავლას applications.ge-ს კურსზე!";
	}
} elseif ($მუშაობა_გვინდა) {
	echo "\nვმუშაობთ";
} else {
	echo "\nდროს ნუ კარგავ!";
}
by Valeri Tandilashvili
2 years ago
2
PHP
If / else
1
by nikoloz nachkebia
2 years ago
0
PHP
PHP If statement
1
by nikoloz nachkebia
2 years ago
0
PHP
User-defined functions
1
by დავით ქუთათელაძე
2 years ago
0
PHP
the continue statement
1
by nikoloz nachkebia
2 years ago
0
PHP
PHP else-if statement
1
by დავით ქუთათელაძე
2 years ago
0
PHP
rules to create php variable
1
by დავით ქუთათელაძე
2 years ago
0
PHP
case sensitivity
1
by nikoloz nachkebia
2 years ago
0
PHP
FOR loop examples
1
Results: 1580