PHP Interview Programs | Part 6

Problem 26: What would be the output of following:

OUTPUT:

1   // $b value will be 1

21  // $c value will be 21 as 2 is concatenated to the value of $b

Problem 27: What would be the output of the following?

OUTPUT:

bool(false)   //  As number precede by 0 leads to an octal number.

bool(true)    // as 0123 is enclosed in quotes so it would be concerted to it’s numeric value which is 123 so it is true.

bool(false)  // it’s false as o123 is quoted and is string so they are not identical.Their data type is different.

Problem 28: What will be the output of the following:

OUTPUT:

bool(true)   //  and operator works as OR because = operator has the precedence over and.

Problem 29: What would be the output of following:

OUTPUT:

Array ( [1] => d ) 

 

Here all keys will be type casted to number 1. but the value the array will hold will be of the data type whose precedence is higher.precedence hirarchy in increment order is as follows:

String(“1”)  => Number(1) => Float(1.5) => bool(true).  so if we omit true element from array then result will be :

Array ( [1] => c ) 

and so like that…..

Problem 30:  Write a program to concatenate two strings character by character. e.g : JOHN + SMITH = JSOMHINTH

Problem 31: Program to find the LCM of two numbers.

<<Previous