php

How to check if a variable is null in PHP

In this tutorial, we are going to see how to check if a variable is null in PHP. You can use PHP’s is_null() function to check if a variable is null or not.

 

How to check if a variable is null in PHP
<?php
	$var = NULL;
	 
	if(is_null($var)){
		echo '$var is null.'. '<br />';
	}
	 
	if(is_null($foo)){
		echo '$foo is null.';
	}
?>

Output:

$var is null.
$foo is null.

 

mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

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