NULL value

Posted on 2007-10-17
Last Modified: 2013-12-13

I need to know what's the right script to check if the value is null or not

$isDefault = NULL
or $isDefault=[NULL]
or $isDefault='NULL'
ot $isDefault==NULL

Question by:usmbay
    LVL 9

    Assisted Solution


    Author Comment

    but in the table looks like this [NULL]

    should I write it null or NULL or there's no different
    LVL 11

    Assisted Solution

    If this is coming from a database query and the value is null, then it will apply null to the value in the array. If it is important to know if the value is in fact null, then you may want to use:
    $isDefault === null // this will check type
    is_null( $isDefault )

    Otherwise values of '' and 0 could also be interpreted as null values.

    And yes, null and NULL are both valid ways of expressing null.
    LVL 17

    Accepted Solution

    if (!$isDefault) {
        echo "The value is Null";

    You need the BANG "!" in front of the variable


    if ($isDefault) {
         echo "the value is not null";

    just the  variable in the if statement will check if the variable has any value.

    though when checking for a null or empty value you should do this
    if ((!$isDefault) || ($isDefault == "")) {
        echo "The value is Null";
    this checks if it is null or is empty, cause sometimes a variable can have a value that is blank and not be null.
    LVL 9

    Assisted Solution

    you could even use the empty($isDefault) function - returns true if empty, null, 0 or 0 sized - but it depends on the actual implementation of your code.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    A colleague recently asked me about how to give his client a small part of the web site that could be completely under the client's control.  Since I have done this sort of thing before to add emergency banners to a web site, I decided I would creat…
    I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now