• Strings and Regular Expressions

      0 comments

    Consider the following script. What line of code should be inserted in the marked location in
    order to display the string php when this script is executed?

    $alpha = 'abcdefghijklmnopqrstuvwxyz';
    $letters = array(15, 7, 15);
    foreach($letters as $val) {
    /* What should be here */
    }

    A. echo chr($val);
    B. echo asc($val);
    C. echo substr($alpha, $val, 2);
    D. echo $alpha{$val};
    E. echo $alpha{$val+1}

    An array can be accessed like this as well. $alpha{$val}

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