Results: 1580
Notes
  • Newest first
  • Oldest first
  • Newest first(All)
  • Oldest first(All)
PHP Class Inheritance
<?php interface AnimalInterface { public function makeSound(); } class Dog implements AnimalInterface { public function makeSound() { echo "Woof! <br />"; } } class Cat implements AnimalInterface { public function makeSound() { echo "Meow! <br />"; } } $myObj1 = new Dog(); $myObj1-> makeSound(); $myObj2 = new Cat(); $myObj2->makeSound(); ?>
by Gabriel Jakhveladze
2 years ago
0
PHP
Object Oriented PHP Tutorial
0
If the current day is Sunday the code will output "I don't worl."
<?php
$d = date("D");
if ($d == "Sun"){
    echo "I don't work". ".";
} 
?>
If the current hour is less than 20, the code will output "I am going to sleep"
<?php
$t = date("H");
if ($t < "22"){
	echo " I am going to sleep";
}
?>
by Mariam Gelkhauri
2 years ago
0
PHP
If Statement
PHP
Object Oriented PHP Tutorial
0
Output "I watch TV" if the current time is less than 20, and "I play a game" otherwise:
<?php
$t = date("H");
if ($t < "18") {
	echo "I watch TV";
} else {
	echo "I play a game";
}
?>
by Mariam Gelkhauri
2 years ago
0
PHP
Object Oriented PHP Tutorial
0
A variable starts with the $ sign, followed by the name of the variable A variable name must start with a letter or the underscore character A variable name cannot start with a number A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ ) Variable names are case-sensitive ($age and $AGE are two different variables)
by Elene Gigauri
2 years ago
0
PHP
0
Rules to create PHP variables
- A variable starts with the $ sign, followed by the name of the variable - A variable name must start with a letter or the underscore character - A variable name cannot start with a number - A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ ) - Variable names are case-sensitive ($my_car, $mycar, $myCar, $MYCAR, $MYcar are four different variables)
 
// Correct Syntax  ($variable_name = "Value";)
    $my_car = "BMW";
   
// Incorect Syntax
    my_car = "BMW";
    $7my_car = "BMW";
    $my&car = "BMW";
by Tornike Kartvelishvili
2 years ago
0
PHP
Variables
0
PHP Variables Scope
PHP's most used variable scopes are: - local - global A variable declared outside a function has a GLOBAL SCOPE and can only be accessed outside a function:
<?php
   $name = "Tornike";  // global scope
   function greeting() {
     echo "Hello " . $name . "!"; // using $name will generate an error
   } 
   greeting();

   echo "Hello" . $name . "!"; // using $name will generate output (Hello Tornike!)
?>
A variable declared within a function has a LOCAL SCOPE and can only be accessed within that function:
<?php
   function greeting() {
     $name = "Tornike";  // local scope
     echo "Hello " . $name . "!";  // using $name inside the function will generate output (Hello Tornike!)
   } 
   greeting();

   echo "Hello" . $name . "!"; // using $name outside the function will generate an error
?>
by Tornike Kartvelishvili
2 years ago
0
PHP
Variables
Variables Scope
0
PHP The global Keyword
The global keyword is used to access a global variable from within a function. To do this, use the global keyword before the variables (inside the function):
<?php
  $x = 70;
  $y = 7;

  function myNum {
    global $x, $y;
    $y = $x + $y;
  }
  
  myNum();
  echo $y; // output is 77
?>
by Tornike Kartvelishvili
2 years ago
0
PHP
Variables
Variables Scope
0
PHP $GLOBALS[index] array
HP also stores all global variables in an array called $GLOBALS[index]. The index holds the name of the variable. This array is also accessible from within functions and can be used to update global variables directly.
<?php
  $x = 70;
  $y = 7;

  function myNum {
    $GLOBALS['y'] = $GLOBALS['x'] + $GLOBALS['y'];
  }
  
  myNum();
  echo $y; // output is 77
?>
by Tornike Kartvelishvili
2 years ago
0
PHP
Variables
Variables Scope
0
PHP The static Keyword
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:
<?php
function myTest() {
  static $x = 0;
  echo $x;
  $x++;
}

myTest(); // output  is 1
myTest(); // output  is 2
myTest(); // output is 3
?>
Then, each time the function is called, that variable will still have the information it contained from the last time the function was called. Note: The variable is still local to the function.
by Tornike Kartvelishvili
2 years ago
0
PHP
Variables
Variables Scope
0
PHP Constants
Constants are similar to variables except that they cannot be changed or undefined after they've been defined. Begin the name of your constant with a letter or an underscore. To create a constant, use the define() function:
define(name, value, case-insensitive)
Parameters: name: Specifies the name of the constant; value: Specifies the value of the constant; case-insensitive: Specifies whether the constant name should be case-insensitive. Default is false; The example below creates a constant with a case-sensitive name:
<?php
  define("georgian_player", "Kvicha Kvaratskhelia");
  echo georgian_player;
  // Outputs "Kvicha Kvaratskhelia"
?>
The example below creates a constant with a case-insensitive name:
<?php
  define("georgian_player", "Kvicha Kvaratskhelia", true);
  echo Georgian_Player;
  // Outputs "Kvicha Kvaratskhelia"
?>
No dollar sign ($) is necessary before the constant name.
by Tornike Kartvelishvili
2 years ago
0
PHP
Variables
0
Results: 1580