What does this PHP sentence mean/do?

Posted on 2011-04-22
Last Modified: 2012-05-11
Dont know very much about PHP this shoule be a straightforward one for anyone familiar with it. Below I am trying to figure out what this line does so I can replicate it in Java.

if (!$power) $power=0;

I think it is saying, If power is null then power is 0.

Can anyone confirm?
Question by:bhession
    LVL 142

    Assisted Solution

    by:Guy Hengel [angelIII / a3]
    if $power is empty, it will set it to 0 ...
    LVL 107

    Expert Comment

    by:Ray Paseur
    If $power is empty, NULL, FALSE or Zero, it will assign the integer value Zero.
    LVL 107

    Accepted Solution

    PHP is a "loosely typed" language, and tests for equality are made with loose typing.  So a not-null string is evaluated the same way as a positive integer, or a TRUE boolean.  This page may be helpful to your understanding of PHP data types.

    HTH, ~Ray

    Author Closing Comment

    Much gratitude, very helpful. Thanks guys

    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

    Join & Write a Comment

    Suggested Solutions

    Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit ( and similar technologies have enjoyed wide adoption, making it possib…
    Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
    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…
    The viewer will learn how to dynamically set the form action using jQuery.

    729 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

    19 Experts available now in Live!

    Get 1:1 Help Now