Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

What will be the values of $a and $b after the code below is executed? Explain your answer.

user-image
Question added by Anirban Chakraborty , Network Administrator , Wipro Limited
Date Posted: 2017/01/17
ibrahim badran
by ibrahim badran , Front & Backend Developer , Freelancer

$a is variable having string as type and contain 1 as value, $b is reference of $a so if we change the value of $b that value of $a is changed automatically because both having the same value.

So $b = '2$b'  = '21' = $a .

Adel Ezat Fawzy Ellozy
by Adel Ezat Fawzy Ellozy , Webdeveloper. , Saudi Arabian Maritiem Sports Federation

$a = '1';   // '1' as string .

$b = &$a; // $b reference to $a

So Both are equal to "21" ;

Jonathan de Flaugergues
by Jonathan de Flaugergues , software engineer , Abbeal

$a = '1'; // $a is a variable type of string with the value '1';

$b = &$a; // $b is the reference of the $a variable.

$b = "2$b"; // $b & $a have for value the string '2' concatenate with the value of the variable $a (string '1')

So, the result is '21'

Ehab  Shaker
by Ehab Shaker , Dot Net Developer , Info Strategic

the result is '21' as a string value

هاشم المشارقة
by هاشم المشارقة , Key Account Manager , Advanced United Systems Ltd. ( A member of Taj Holding Group)

Pay attention to tha last line of the code.

$b = "2$b" (String)

More Questions Like This

Do you need help in adding the right keywords to your CV? Let our CV writing experts help you.