php inbuilt function

isset() function

The isset () function is used to check a variable is set or not.

Returns TRUE if var exists and has value other than NULL, FALSE otherwise.

File name : index.php

<?php
$var1 = 'test';
var_dump(isset($var1));
if(isset($var1))
{
echo "varible is set";
}
else
{
echo "variable is not set.";
} ?>

Output :-

bool(true)
varible is set

File name : index.php

<?php
$var = "";
if (isset($var)) {
echo "variable is set.";
}
else {
echo "variable is Not set.";
}

?>

Output :-

variable is set.

File name : index.php

<?php
if(isset($_POST['submit']))

{
$name = $_POST['fname'];
echo $name;
}
else
{
echo "Form is not submit";
}

?>

<html>
<head>
<title></title>
</head>
<body>
<form action="" method="post">
<input type="text" name="fname"/><br/>
<input type="submit" name="submit" value="Submit"/>
</form>
</body>
</html>

Output :-

if form is sumbit then display name other wise form is not submit;

empty() function

The empty() function is used to check a variable is empty or not.

empty() does not generate a warning if the variable does not exist.

File name : index.php

<?php
$var = "mahtab";
$var1 = 0;
// Evaluates to true because $var is empty
if (empty($var1))
{
echo 'variable is empty.';
}
else
{
echo "variable is not empty";
}

?>

Output :-

variable is empty

var_dump() function

The var_dump() function is used to display structured information (type and value) about one or more variables.

File name : index.php

<?php
$var_name1=678;
$var_name2="a678";
$var_name3="678";
$var_name4="itechtuto.com";
$var_name5=698.99;
$var_name6=+125689.66;
echo var_dump($var_name1)."<br>";
echo var_dump($var_name2)."<br>";
echo var_dump($var_name3)."<br>";
echo var_dump($var_name4)."<br>";
echo var_dump($var_name5)."<br>";
echo var_dump($var_name6)."<br>";
?>

Output :-

int(678)
string(4) "a678"
string(3) "678"
string(14) "itechtuto.com"
float(698.99)
float(125689.66)

unset() function

The unset() function destroys (remove) a given variable.

File name : index.php

<?php
$var = "mahtab";
unset($var);
echo $var;

if(isset($var))
{
echo "yes";
}
else
{
echo "No";
}

?>

Output :-

Notice: Undefined variable: var in D:\xampp\htdocs\Image_GD\index.php on line 4
No

print_r() function

The print_r() function is used to print human-readable information about a variable.

File name : index.php

<?php
$var1='abc';
$var2=123.33;
print_r($var1);
echo'<br>';
print_r($var2);
echo'<br>';
$abc = array('Subj1'=>'Physics','Subj2'=>'Chemistry','Subj3'=>'Mathematics','Class'=>array(5,6,7,8));
print_r($abc);
?>

Output :-

abc
123.33
Array ( [Subj1] => Physics [Subj2] => Chemistry [Subj3] => Mathematics [Class] => Array ( [0] => 5 [1] => 6 [2] => 7 [3] => 8 ) )

is_array() function

The is_array() function is used to find whether a variable is an array or not.

File name : index.php

<?php
$var_name=array('A','B','C');
if (is_array($var_name))
echo 'This is an array....';
else
echo 'This is not an array....';
?>

Output :-

This is an array....

PHP unlink() Function

The unlink() function deletes a file.

File name : index.php

<?php
$file = "test.txt";
if (!unlink($file))
{
echo ("Error deleting $file");
}
else
{
echo ("Deleted $file");
}
?>

Output :-


count() Function

the count() function is used to count the number of elements in an array.

File name : index.php

<!DOCTYPE html>
<html>
<body>
<?php
$students=array("mahtab","Habib","Sara","Arham");
echo count($students);
?>
</body>
</html>

Output : 4

rand () Function

The rand() function is used to generates a random integer.

File name : index.php

<!DOCTYPE html>
<html>
<body>
<?php
$random_number=rand(1000, 9999);//4 digit number
echo $random_number;



$random_number=rand(100000, 999999);//6 digit number
echo $random_number; ?>
</body>
</html>

mt_rand () Function

The mt_rand() function also generates random integer but it is more powerful and generate 4 times faster than rand() function.

File name : index.php

<!DOCTYPE html>
<html>
<body>
<?php
$random_number=mt_rand(1000, 9999);
echo $random_number;
?>
</body>
</html>

round() function

The PHP round() function rounds a floating number. It Returns the rounded value of number to specified precisions.

File name : index.php

<!DOCTYPE html>
<html>
<body>
<?php
echo(round(0.75) . "<br>");
echo(round(1.20) . "<br>");
echo(round(4.96754,2) . "<br>");
echo(round(7.045,2) . "<br>");
echo(round(7.055,2));
?>
</body>
</html>

date_diff() function

the date_diff() function used to returns the difference between two DateTime.

File name : index.php

<!DOCTYPE html>
<html>
<body>
<?php
$date1=date_create("2018-11-12");
$date2=date_create("2018-12-12");
$diff=date_diff($date1,$date2);
$difference=$diff->format("%R%a days");
echo substr("$difference",1);
?>
</body>
</html>

trim() function

The trim() function is used to removes whitespace and other predefined characters from both sides of a string in PHP.

File name : index.php

<!DOCTYPE html>
<html>
<body>
<?php
$str = "Hello World!";
echo $str . "<br>";
echo trim($str,"Hello"). "<br>";
?>
</body>
</html>

ltrim() Function

The ltrim() function is used to removes whitespace or other predefined characters from the left side of a string.

File name : index.php

<!DOCTYPE html>
<html>
<body>
<?php
$str = "Students Tutorial";
echo $str . "<br>";
echo ltrim($str,"Students"). "<br>";
?>
</body>
</html>

rtrim() Function

The rtrim() function is used to removes whitespace or other predefined characters from right sides of a string.

File name : index.php

<!DOCTYPE html>
<html>
<body>
<?php
$str = "Students Tutorial";
echo $str . "<br>";
echo rtrim($str,"Tutorial"). "<br>";
?>
</body>
</html>





Previous Next


Trending Tutorials




Review & Rating

0.0 / 5

0 Review

5
(0)

4
(0)

3
(0)

2
(0)

1
(0)

Write Review Here