search for in the  
<is_longis_numeric>
Last updated: Thu, 19 May 2005

is_null

(PHP 4 >= 4.0.4, PHP 5)

is_null --  Finds whether a variable is NULL

Description

bool is_null ( mixed var )

Finds whether the given variable is NULL.

Parameters

var

The variable being evaluated.

Return Values

Returns TRUE if var is null, FALSE otherwise.



User Contributed Notes
is_null
disappear at dissolution dot ath dot cx
08-May-2005 10:51
i wrote a small case study to compare is_null / == NULL / === NULL

Here's the code ::

<?php

   $Array
= array ( 0 , '' , FALSE , NULL ) ;
  
$ArrayCount = count ( $Array ) ;

  
$String .= '$Array = ' . "array ( 0 , '' , FALSE , NULL ) <br><br>" ;

   for (
$i = 0 ; $i < $ArrayCount ; $i++ )

   {

       if (
$Array [ $i ] == NULL )

       {

          
$String .= '$Array [ $i ] == NULL :: $Array [ ' . $i . ' ] <br>' ;

       }

       if (
$Array [ $i ] === NULL )

       {

          
$String .= '$Array [ $i ] === NULL :: $Array [ ' . $i . ' ] <br>' ;

       }

       if (
is_null ( $Array [ $i ] ) )

       {

          
$String .= 'is_null ( $Array [ $i ] ) :: $Array [ ' . $i . ' ] <br>' ;

       }

   }

   echo
$String ;

?>

Here's the results i got ::

$Array = array ( 0 , '' , FALSE , NULL )

$Array [ $i ] == NULL :: $Array [ 0 ]
$Array [ $i ] == NULL :: $Array [ 1 ]
$Array [ $i ] == NULL :: $Array [ 2 ]
$Array [ $i ] == NULL :: $Array [ 3 ]
$Array [ $i ] === NULL :: $Array [ 3 ]
is_null ( $Array [ $i ] ) :: $Array [ 3 ]
jbeninger at nospam tiberDot ca
11-Apr-2004 04:18
Regarding the function that returns a default value if the passed value is null: I like my functions names to bear resemblance to their function (Nz doesn't really pass that test). 

I've got a similar function but have called it "if_null" - after the SQL function that serves the same purpose.
michael at cannonbose dot com
30-Dec-2003 11:42
Regarding avoidance of NULLs in your MySQL queries, why not use  IS NULL and IS NOT NULL in your WHERE clauses.

SELECT *
FROM someDatabase
WHERE someAttribute IS NOT NULL

Cheers,

Michael
galardi at dii dot unisi dot it
19-Aug-2002 12:43
The following function is useful for set a variable to a default value the case it contains null:

function Nz($TestVar,$ValueIfNull)
{
   if (is_null($TestVar))
     return $ValueIfNull;
   else
     return $TestVar;
}

I have used it to ensure to always write something in the cells of a table; otherwise Netscape doesn't show the color of cell background. Ex:

<TD valign="top" BGCOLOR="#F0F0F0">
<?echo Nz($row2["Name"],"&nbsp;");?>
</TD>
dstone[at]NOSPAMviatraining.com
07-Jun-2002 08:19
The above example is a little wrong. An empty value is not equivalent to null in mysql. To get not null in mysql use "... where column is not null"

If you are doing a left join in mysql, no matched entry returns a null, where if you had a matched entry and were asking about a text field, '' might match, so != '' is different than is not null
thepissboy at hotmail dot com
06-May-2002 11:00
After pulling out most of my hair weeding through really unintelligible crap:

HERE'S AN EASY WAY TO ELIMINATE NULL VALUES FROM YOUR ARRAYS!!

$result = mysql_query("SELECT * FROM someDatabase WHERE page_title != ''",$db);
   if ($myrow = mysql_fetch_array($result)) {
  
   printf("%s\n", $myrow["page_title"]);
   }
  
   else {
  
   printf("Scratch head");
   }

It's all in the SQL Query line. The code says don't bring back anything that's empty!!!!

So hopefully, some of us will be able to get back to being in a hurry.
uioreanu at hotmail dot com
23-Mar-2001 08:36
Don't try to test
if ($intSomething==NULL) {
 ...
}
use is_null() instead.
The first statement misses 0 values.

Regards,
Calin

[Ed. note: this is because == tests for equivalence of value, but not type. NULL evaluates to
false, as does 0, so NULL == 0 is true--even though 0 is type int and NULL is type null.
You should use either is_null() as noted or ===, which returns true only if its operands are
equal and of the same type.]

<is_longis_numeric>
 Last updated: Thu, 19 May 2005
Copyright © 2001-2005 The PHP Group
All rights reserved.
This unofficial mirror is operated at: The Server Pages
Last updated: Thu May 19 17:35:34 2005 CDT