phpnullisnull

Convert native null to string "null"


Is it possible to convert null to string with php?

For instance,

$string = null;

to

$string = "null";

Solution

  • Am I missing something here?

    if ($string === null) {
        $string = 'null';
    }
    

    was thinking something shorter...

    You can also use a ternary operator:

    $string = is_null($string) ? 'null' : $string;
    

    Your call.