• Strings and regular expressions

      0 comments

    What will be the answer of the following code snippet?

    echo 'Testing ' . 1 + 2 . '45';
    

    Simply you will give the answer as : Testing 345

    But the answer is : 245

    That is because you can not sum a number with a string. The first part, before the plus mark is a string though there is 1 there.
    So engine will simply get it as 0 and the latter part as 245. so answer will be 245.

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