php is set – How to check whether a variable is set or not in PHP?

Rate this post

php is set used to determine that a variable is set or not. The isset() function is an inbuilt function in PHP which checks whether a variable is set and is not NULL.

php is set – isset() and !empty() function in PHP

check whether a variable is set or not in PHP – Use the PHP isset() function

PHP isset() function syntax

isset(“variable”);

PHP isset() – Check If Variable Is Set

Use the PHP isset() function

<?php
$str1 = '';
if(isset($str1)){
    echo 'This slogen is displayed, because the $str1 is set.';
}
echo "<br>";
 
$str2 = 'Welcome TO Pakainfo.com!';
if(isset($str2)){
    echo 'This slogen is displayed, because the $str2 is set.';
}
echo "<br>";
 
// Unset the striable
unset($str2);
 
if(isset($str2)){
    echo 'This slogen is displayed, because the $str2 is set.';
} else{
    echo 'This slogen is displayed, because the $str2 is not set.';
}
echo "<br>";
 
$str3 = NULL;
if(isset($str3)){
    echo 'This slogen is displayed, because the $str3 is set.';
} else{
    echo 'This slogen is displayed, because the $str3 is not set.';
}
?>

PHP isset() Example

<?php

$str = 'meera'; 
var_dump(isset($str));

?>

//The output is :
boolean true

Free Live Chat for Any Issue

Checking if a Cookie is Set

Use the PHP isset() function upon the superglobal $_COOKIE variable to check if a cookie is set.

Read Also:  List of all WordPress WooCommerce hooks

Example:

if (isset($_COOKIE['member'])) {

    echo 'Member is ' . $_COOKIE['member'];
else {
    echo 'Member is not sign in';
}

// PHP 7.0+
echo 'Member is ' . $_COOKIE['member'] ?? 'Member is not sign in'; 

Download

I hope you get an idea about php is set.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.