Results: 1580
Notes
  • Newest first
  • Oldest first
  • Newest first(All)
  • Oldest first(All)
➤ 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
➤ 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
-.-. --- -. ...- . .-. - / - . -..- - / - --- / -- --- .-. ... . / -.-. --- -.. . 🔥 CODE
➤ Convert text to Morse code.
// The array contains only numbers and alphabets.
$morse = [
	"A" => ".-","B" => "-...","C" => "-.-.","D" => "-..",
	"E" => ".","F" => "..-.","G" => "--.","H" => "....",
	"I" => "..","J" => ".---","K" => "-.-","L" => ".-..",
	"M" => "--","N" => "-.","O" => "---","P" => ".--.",
	"Q" => "--.-","R" => ".-.","S" => "...","T" => "-",
	"U" => "..-","V" => "...-","W" => ".--","X" => "-..-",
	"Y" => "-.--","Z" => "--..",1 => ".----",2 => "..---",
	3 => "...--",4 => "....-",5 => ".....",6 => "-....",
	7 => "--...",8 => "---..",9 => "----.",0 => "-----",
];
function convert_text_to_morse($str){
	global $morse;
	$result = "";
	for ( $i = 0; $i < strlen($str); $i++ ){
		if( $str[$i] == " " ) $result .= " / ";
		else {
			$result .= $morse[strtoupper($str[$i])]." ";
		}
	}
	return $result;
}
// print_r ($morse);
echo convert_text_to_morse("Hello world");
// outputs:   .... . .-.. .-.. ---  / .-- --- .-. .-.. -.. 
echo "\n";
echo convert_text_to_morse("404 ERROR");
// outputs :   ....- ----- ....-  / . .-. .-. --- .-. 
by Levani Makhareishvili
2 years ago
0
PHP
1
➤ This function compares the values of two (or more) arrays, and return an array that contains the entries from array1 that are not present in array2 or array3, etc. Syntax:
array_diff(array1, array2, array3, ...)
For instance:
$array1 = ["A" => 10, "B" => 20, "C" => 30, "D" => 40];
$array2 = ["A" => 10, "B" => 20, "C" => 30];
$result_array = array_diff($array1,$array2);
print_r ($result_array);
// outputs :  [D] => 40
by Levani Makhareishvili
2 years ago
0
PHP
Function
1
➤ The array_flip() function flips/exchanges all keys with their associated values in an array. Syntax:
array_flip(array)
For instance:
$array = ["A" => 10, "B" => 20, "C" => 30, "D" => 40];
$result_array = array_flip($array);
print_r ($result_array);
// outputs : 
//    [10] => A
//    [20] => B
//    [30] => C
//    [40] => D
by Levani Makhareishvili
2 years ago
0
PHP
Function
1
➤ The strtr() function translates certain characters in a string. Syntax:
strtr(string,from,to)
For instance:
// Replace the characters "1p" in the string with "lr":
$string = "He11o wopld";
$result_string = strtr ($string,"1p","lr");
echo $result_string;
• If the from and to parameters are different in length, both will be formatted to the length of the shortest.
by Levani Makhareishvili
2 years ago
0
PHP
Function
1
➤ The strpos() function finds the position of the first occurrence of a string inside another string. Syntax:
strpos(string,find,start) 
// start is optional. Specifies where to begin the search. 
For instance:
// Find the position of the first occurrence of "lo" inside the string:
$string = "Hello world";
$result_string = strpos ($string,"lo");
echo $result_string;
//  outputs :  3
➤ strrpos() - Finds the position of the last occurrence of a string inside another string (c-sensitive) ➤ stripos() - Finds the position of the first occurrence of a string inside another string (c-insensitive) ➤ strripos() - Finds the position of the last occurrence of a string inside another string (c-insensitive)
by Levani Makhareishvili
2 years ago
0
PHP
Function
1
➤ The ctype_upper() function used to check each and every character of a given string is in upper case or not. If the string in upper case then it returns TRUE otherwise returns False. Syntax:
ctype_upper (string text)
For intsnace:
$string = "IAMHUNGRYYYYYY";
$result = ctype_upper ($string);
echo $result;
// outputs :   1  (True)
// All characters of  "IAMHUNGRYYYYYY" in UPPERCASE
➤ The ctype_lower() function used to check each and every character of a given string is in lower case or not.
by Levani Makhareishvili
2 years ago
0
PHP
1
➤ The ucfirst() function converts the first character of a string to uppercase. Syntax:
ucfirst(string)
For instance:
$string = "i am hungry !";
$result = ucfirst ($string);
echo $result;
// outputs :   I am hungry !
➤ lcfirst() - converts the first character of a string to lowercase. ➤ ucwords() - converts the first character of each word in a string to uppercase.
by Levani Makhareishvili
2 years ago
0
PHP
Function
1
╰┈➤ Create a function that accepts a string, checks if it's a valid email address and returns either
true 
or
false
function validateEmail($email) {
    if ($email == "") {
	return false; "\n";
    }
    $reversed = strrev($email);
    $position = strpos($email, "@");
	if (substr_count($email, "@") == 1 && $position > 0 && ord($email[$position + 1]) > 96 
            && ord($email[$position+1])<123 && substr_count($email, ".") > 0 
            && strpos($reversed, ".") < strpos($reversed, "@") - 1 && $reversed[0] != ".")  {
	        return true; "\n";
	        }
    return false; "\n";
}
echo(validateEmail('@edabit.com')); //false
echo(validateEmail('bill.gates@microsoft.com'));//true
by Luka Khitaridze
2 years ago
0
PHP
Problem solving
1
Results: 1580