• heredoc syntax

      0 comments

    “heredoc” syntax can be used to declare complex strings,

    What will out put the following code snippet?

    <?php
    $who = "questions";
    echo <<<TEXT
    So I said, "php interview $who"
    TEXT;
    ?>

    Answer – So I said, “php interview questions”

    In general, the functionality of this heredoc syntax is similar to double quotes.

  • 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.