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

  • 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”;