‘0’ as a string with empty() in PHP

I want a 0 to be considered as an integer and a '0' to be considered as a string, but empty() considers the '0' as a string in the example below,

$var = '0';

// Evaluates to true because $var is empty
if (empty($var)) {
    echo '$var is empty';

How can I 'make' empty() to take '0's as strings?

Read more here: https://stackoverflow.com/questions/4139301/0-as-a-string-with-empty-in-php

Content Attribution

This content was originally published by laukok at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: