skip to Main Content

Example below:

$var1 = 'This is how the word';
$var2 = NULL;
$var3 = 'is used in a string.';

echo "$var1 $var2 $var3";

Desired result:

This how is how the word NULL is used in a string.

Actual result:

This is how the word  is used in a string.

Would like to do the manipulation on the $var2 = NULL; line if possible. I’ve tried adding single and double quotes – single leads to …word ‘NULL’ is… and double is the same as above.

2

Answers


  1. Just make NULL a string if you need that to visually print.

    <?php
    $var1 = 'This is how the word';
    $var2 = 'NULL';
    $var3 = 'is used in a string.';
    
    echo "$var1 $var2 $var3";
    ?>
    

    but if you are debugging and need to see what boolean is returned, than var_dump or at least print_r are your friends.

    $var2 = NULL;
    
    var_dump($var2);
    
    print_r($var2);
    
    Login or Signup to reply.
  2. Either the question itself is confusing or the approach towards it is confusing.

    Why are you even using 3 variables.

    Just do it like this.

    <?php
    echo "This how is how the word NULL is used in a string.";
    ?>
    

    AND/OR

    If you are looping through lots of words that goes in the middle.

    Just use a small if/else statement inside the loop when the word is NULL.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search