Results: 1578
Notes
  • Newest first
  • Oldest first
  • Newest first(All)
  • Oldest first(All)
➤ Clock time can get using microtime() function. First use it before starts the script and then at the end of the script. Then using formula (End_time – Start_time). ➤ The microtime() function returns the current Unix timestamp with microseconds. By default, the microtime() function returns the time as a string, but if it is set to TRUE, then the function returns the time as a float. So the default is FALSE. For instance:
// Starting clock time in seconds
$start_time = microtime(true);
$result = 0;
for( $i = 0; $i <=1000000; $i++ )
{
	$result += $i;
} 
// End clock time in seconds
$end_time = microtime(true);
  
// Calculate script execution time
$execution_time = ($end_time - $start_time);
echo " Execution time of script = ".$execution_time." sec";
by Levani Makhareishvili
2 years ago
0
PHP
Function
1
➤ The global keyword imports variables from the global scope into the local scope of a function. For instance:
$x = 10;
$y = 5;
function additional_first(){
	return $x + $y;
}
echo additional_first();
// outputs :  Undefined variables $x and $y

function additional_second(){
	
global $x,$y;
return $x + $y; } echo additional_second(); // outputs : 15
by Levani Makhareishvili
2 years ago
0
PHP
1
Concatenation using Double Quotes " " CODE
• An integer is converted to a string.
$int = 10;
echo "I.  Value of \$int is:  $int\n";
echo gettype("$int"); // outputs :  string
• An integer is NOT converted to a string.
$int = 10;
echo "II. Value of \$int is:  ".$int;
by Levani Makhareishvili
2 years ago
0
PHP
1
➤ Alphabet triangle pattern using range() function
$alpha = range('A', 'Z');  
for( $i = 0; $i < 10; $i++ ) {   
  for( $k = 10; $k > $i ; $k-- ){  
    echo $alpha[$i];  
    }  
    echo "\n";  
}  
Outputs :
AAAAAAAAAA
BBBBBBBBB
CCCCCCCC
DDDDDDD
EEEEEE
FFFFF
GGGG
HHH
II
J
by Levani Makhareishvili
2 years ago
0
PHP
1
➤ The range() function creates an array containing a range of elements.This function returns an array of elements from low to high. If the low parameter is higher than the high parameter, the range array will be from high to low. Syntax:
range(low, high, step) 
// third parameter is optional, Specifies the increment used in the range. Default is 1
For instance:
// Return an array of elements from "0" to "20".increment by 5.
$number = range(0,20,5);
print_r ($number);
// outputs :  0 5 10 15 20

// Using letters - return an array of elements from "a" to "k"
$letter = range("a","k");
print_r ($letter);
// outputs :  a b c d e f g h i j k
by Levani Makhareishvili
2 years ago
0
PHP
Function
1
➤ Fibonacci series is the one in which you will get your next term by adding previous two numbers. For instance:
$num = 0;  
$n1 = 0;  
$n2 = 1;  
echo "Fibonacci series for first 20 numbers: \n";  
echo $n1.' '.$n2.' ';  
while ( $num < 18 )  
{  
    $n3 = $n2 + $n1;  
    echo $n3.' ';  
    $n1 = $n2;  
    $n2 = $n3;  
    $num = $num + 1;  
}
// 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 
by Levani Makhareishvili
2 years ago
0
PHP
1
╰┈➤ When variables are passed by reference, use & (ampersand) symbol need to be added before variable argument
function print_string(&$string) {
    $string = "Function string \n";
    echo($string);
}
$string = "Global string \n";
print_string($string);
echo($string);
// outputs: Function string, Global string
► Scope of both global and function variable becomes global as both variables are defined by same reference. Therefore, whenever global variable is change, variable inside function also gets changed. ◄
If we delete & (ampersand) symbol before variable, it outputs: Function string, Global string
by Luka Khitaridze
2 years ago
0
PHP
Variable
0
function is_multi($array) {
    $filter = array_filter($array, 'is_array');
    print_r($filter);
    if(count($filter) > 0) {
    	return true;
    }
    return false;
}
var_dump(is_multi([
	"Valeri"=> [
		"weight"=>77, 
	],
	"Giorgi"=> [
		"weight"=>87, 
		"parents"=> [
			"father"=>"Daviti",
			"mother"=>"Mariami",
		]
	],
]));
by Luka Khitaridze
2 years ago
0
PHP
Array
0
➤ The rand() function generates a random integer. If you want a random integer between 10 and 100 (inclusive), use rand (10,100). Syntax:
rand();
or
rand(min,max);
For instance:
$x = rand(0,10);
echo $x;
// outputs :  random integer between 0 and 10 (inclusive)
by Levani Makhareishvili
2 years ago
0
PHP
Function
1
➤ Two numbers can be swapped or interchanged. It means first number will become second and second number will become first. For instance: • Swapping Using Third Variable
$x = 5;  
$y = 10;  
// Swapping Logic  
$temp = $x;  
$x = $y;  
$y = $temp;  
echo "After swapping: ";  
echo "\n x = $x \n y = $y";  
// outputs :  x = 10   y = 5
• Swap two numbers without using a third variable - Using arithmetic operation + and ?
$x = 5;  
$y = 10;  
$x = $x + $y;  // 15
$y = $x - $y;  // 5
$x = $x - $y;  // 10
echo "After swapping: ";  
echo "\n x = $x \n y = $y";  
// outputs :  x = 10   y = 5
- Using arithmetic operation * and /
$x = 5;  
$y = 10;  
$x = $x*$y;  // 50
$y = $x/$y;  // 5
$x = $x/$y;  // 10
echo "After swapping: ";  
echo "\n x = $x \n y = $y";  
// outputs :  x = 10   y = 5
by Levani Makhareishvili
2 years ago
0
PHP
1
Results: 1578