• variable interpolation

      2 comments


    Using variable interpolation how we can print the following String?

    “I am visiting the php interview questions website”.
    The word “question” is inside a variable,
    $a = ‘question’;

    Answer is just,
    echo “I am visiting the php interview {$a}s website”;

  • strings and variable interpolation

      0 comments

    Basically there are 2 methods how we can define strings,
    - Simple strings
    - Complex strings

    In a php interview, even a well experienced php programmer might forget how this works,
    For an example,
    a) echo “Hello $what\n”;
    b) echo ‘Hello $what\n’;

    $what = “World”;

    Which will print correctly in to the browser as “Hello World” followed by a new line.
    Is it a) or b) ?

    The answer is “a”. That is because simple string will print almost all characters literally, where complex string allows special escape sequences to insert special characters.