222k views
0 votes
What will be the output of the following code? <?php $foo = 'Bob'; $bar = $foo; $bar = "My name is $bar"; print $bar; print $foo; ?>

a. Error
b. My name is BobBob
c. My name is BobMy name is Bob
d. My name is Bob Bob

User PRF
by
5.9k points

2 Answers

6 votes

Answer:

c

Step-by-step explanation:

error

User Oldrinmendez
by
4.9k points
6 votes

Answer: b. My name is BobBob

Explanation:

  • $foo = 'Bob'; // Assigns foo variable the value Bob
  • $bar = $foo; // Assigns the value of foo to bar
  • $bar = "My name is $bar"; //changes the $bar this is the way to include variables directly in the string.
  • print $bar; // this prints My name is and moves to the variable $bar which prints the value of $bar which is the value of $foo i.e. Bob
  • print $foo; // prints another Bob
User Onizukaek
by
5.7k points