• String Concatenation and regular expressions

      0 comments

    Following question were asked in a technical php interview question paper

    Which of the following will not combine strings $s1 and $s2 into a single string?


    $s1 = 'a';
    $s2 = 'b';
    A. $s1 + $s2
    B. "{$s1}{$s2}"
    C. $s1.$s2
    D. implode('', array($s1,$s2))
    E. All of the above combine the strings

    You can not concatenate 2 string using “+”. The answer will be “0″; so here the answer is A.

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