• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Programming Expert

Solving All of Your Programming Headaches

  • HTML
  • JavaScript
  • jQuery
  • PHP
  • Python
  • SAS
  • Ruby
  • About
You are here: Home / PHP / In PHP isset Method is Used For Checking if Variable is Defined

In PHP isset Method is Used For Checking if Variable is Defined

August 8, 2022 Leave a Comment

In PHP, the isset() method is used for checking if one or more variables have been declared and are not null.

$variable = "I'm a variable";

if (isset($variable)) {
    echo "variable has been declared!";
} else {
   echo "variable hasn't been declared!"
}

if (isset($variable, $another_variable)) {
    echo "all variables have been declared!";
} else {
   echo "all variables haven't been declared!"
}

//Output:
variable has been declared!
all variables haven't been declared!

In php, the isset() method is used for checking if variables have been defined or not.

The isset() function in php takes one or more variables and checks to see if each variable is declared and is different than null.

isset() returns true if the variable exists and false if the variable hasn’t been declared or is null.

If multiple variables are provided, isset() returns true only when all variables passed have been declared.

Below are some examples of using isset() in php to check if one or more variables have been declared.

$variable = "I'm a variable";

if (isset($variable)) {
    echo "variable has been declared!";
} else {
   echo "variable hasn't been declared!"
}

if (isset($variable, $another_variable)) {
    echo "all variables have been declared!";
} else {
   echo "all variables haven't been declared!"
}

$another_variable = "Another variable";

if (isset($variable, $another_variable)) {
    echo "all variables have been declared!";
} else {
   echo "all variables haven't been declared!"
}

//Output:
variable has been declared!
all variables haven't been declared!
all variables have been declared!

Hopefully this article has been useful for you to learn that in PHP, the isset() method allows you to check if variables have been declared.

Other Articles You'll Also Like:

  • 1.  Delete Cookie Using php
  • 2.  php ceil – Round Up and Find the Ceiling of a Number in php
  • 3.  How to Add Items to Array in php
  • 4.  php Absolute Value with abs Function
  • 5.  php in_array – Check If Value is in php Array
  • 6.  php Print Array – How to Print All Elements in Array
  • 7.  Get Current Location Latitude Longitude in php
  • 8.  php atan2 – Find Arctangent of the Quotient of Two Numbers
  • 9.  php is_array() Function – Check if Variable is Array in php
  • 10.  php e – Using M_E and exp() Function to Get Euler’s Constant e

About The Programming Expert

The Programming Expert is a compilation of a programmer’s findings in the world of software development, website creation, and automation of processes.

Programming allows us to create amazing applications which make our work more efficient, repeatable and accurate.

At the end of the day, we want to be able to just push a button and let the code do it’s magic.

You can read more about us on our about page.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

About The Programming Expert

the programming expert main image

Welcome to The Programming Expert. We are a group of US-based programming professionals who have helped companies build, maintain, and improve everything from simple websites to large-scale projects.

We built The Programming Expert to help you solve your programming problems with useful coding methods and functions in various programming languages.

Search

Learn Coding from Experts on Udemy

Looking to boost your skills and learn how to become a programming expert?

Check out the links below to view Udemy courses for learning to program in the following languages:

Copyright © 2023 · The Programming Expert · About · Privacy Policy