Results: 1578
Notes
  • Newest first
  • Oldest first
  • Newest first(All)
  • Oldest first(All)
➤ By using the is_null function, we can check whether the variable is NULL or not. returns true if var is null, otherwise false. • returns true if parameter is null, otherwise false.
$bool = TRUE;  
if (is_null($bool))  
{
	echo 'Variable is  NULL';  
}
else 
{
	echo 'Variable is not NULL';  
}  
// outputs :  Variable is not NULL
by Levani Makhareishvili
2 years ago
0
PHP
Function
1
array_unique($arrary) function;
1. <?php function removeDuplicates($nums){ $nums=array_unique($nums); return $nums; } print_r (removeDuplicates([3, 5, 1,2,3, 5])); ?> 2. <?php function removeDuplicates($nums){ $result=[]; foreach ($nums as $num){ if (!in_array($num, $result)){ $result[]=$num; } } return $result; } print_r (removeDuplicates([3, 5, 1,2,3, 5])); ?>
by Anna Tukvadze
2 years ago
0
PHP
26. Remove Duplicates from Sorted Array
Object Oriented PHP Tutorial
0
➤ PHP also supports recursive function call. In such case, we call current function within function. It is also known as recursion. For instance:
function display( $number ) {    
    if( $number <= 10 ){    
     echo "$number";    
     display ($number+1 );    
    }
}    
display(0);  
// outputs :  012345678910
by Levani Makhareishvili
2 years ago
0
PHP
Function
1
➤ PHP supports variable length argument function. It means you can pass 0, 1 or n number of arguments in function. To do so, you need to use 3 ellipses (dots) before the argument name. For instance:
function print_arr(...$numbers) {  
    foreach ($numbers as $element) {  
        echo $element."\n";  
    }  
}  
echo print_arr(1, 2, 3, 4);  
// outputs :   1 2 3 4
by Levani Makhareishvili
2 years ago
0
PHP
Function
1
sqrt() and floor()
function mysqrt($x){ $x=sqrt($x); $x=floor($x); return($x); } echo mySqrt($x);
by Anna Tukvadze
2 years ago
0
PHP
Object Oriented PHP Tutorial
0
➤ PHP allows you to define default argument values. In such case, if you don't pass any value to the function, it will use default argument value. For instance:
function addition( $x = 10 ){  
	echo $x + 10;  
}  
addition(40); // outputs :  50
addition(); // passing no value. outputs :  20
function addition( $x = 10, $y = 20 ){  
	echo $x + $y;  
}  
addition(5); // passing one argument. outputs :  25
addition(); // passing no value. outputs :  30
by Levani Makhareishvili
2 years ago
0
PHP
Function
1
➤ Using
intval()
function. • To convert string to integer using PHP built-in function, intval(), provide the string as argument to the function. The function will return the integer value corresponding to the string content.
$number_str = "10";
$int_number = intval($number_str);
echo gettype($int_number); // outputs:  integer
➤ Using explicit Casting. • To convert string to integer using Type Casting, provide the literal (int) along with parenthesis before the string literal. The expression returns integer value of the string.

$str = 10;
$number = (int)$str;
echo gettype($number); // outputs:  integer
by Levani Makhareishvili
2 years ago
0
PHP
Function
1
➤ Using
strval()
function. • The strval() function is an inbuilt function in PHP and is used to convert any scalar value (string, integer, or double) to a string. We cannot use strval() on arrays or on object, if applied then this function only returns the type name of the value being converted.
$number = 10;
// converts integer into string
$str = strval($number);
echo gettype($str); // outputs:  string
➤ Using inline variable parsing. • When you use Integer inside a string, then the Integer is first converted into a string and then prints as a string.
$integer = 10;
$str = "$integer";
echo gettype($str); // outputs:  string
➤ Using explicit Casting. • Explicit Casting is the explicit conversion of data type because the user explicitly defines the data type in which he wants to cast. We will convert Integer into String.
$num = 5;
$str = (string)$num; // or String
echo gettype($str); // outputs:  string
by Levani Makhareishvili
2 years ago
0
PHP
Function
1
Remove element without loop CODE
// The array_diff() function compares the values of two (or more) arrays, and returns the differences. // Input: nums = [0,1,2,2,3,0,4,2], val = 2 // output: nums = [0,1,3,0,4]
function removeElement($nums, $val) {
    return array_diff($nums, [$val]);   
}
print_r(removeElement([0,1,2,2,3,0,4,2], 2);
// runtime 7ms
by Luka Khitaridze
2 years ago
0
PHP
Array
0
Length of last word CODE
<?php
function lengthOfLastWord1($s) {
        $words = str_word_count($s,1);  //returns words in array
        //(function returns an array with the words from the string) 
        $wordCount = str_word_count($s); //counts words in text 
        $lastW =  $words[$wordCount-1];//returns last word
        $lastWLen = strlen($lastW); //The last word length
        $lastResult = "The last word is ".'"'.$lastW.'"'." with length $lastWLen";
        return  $lastWLen;
        return $lastResult;      
by Guram Azarashvili
2 years ago
0
PHP
Solutions
0
Results: 1578