ابدأ بالتواصل مع الأشخاص وتبادل معارفك المهنية

أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.

متابعة

What will be the values of $a and $b after the code below is executed? Explain your answer. $a = '1'; $b = &$a; $b = "2$b";

user-image
تم إضافة السؤال من قبل aneri parekh
تاريخ النشر: 2022/12/05
AHMAD ALSHATANAWI
من قبل AHMAD ALSHATANAWI , WEB MARKETING & SEO SPECIALIST , Creativo GBM

After the code is executed, the value of $a will be '1' and the value of $b will be '21'.

 

In the first line, the variable $a is assigned the string value '1'.

 

In the second line, the variable $b is assigned a reference to the variable $a. This means that $b and $a both point to the same memory location and any changes made to the value stored at that memory location will be reflected in both variables.

 

In the third line, the string "2" is concatenated with the value of $b (which is a reference to the value of $a) to create the new string '21'. This new string is then assigned to $b. However, since $b is a reference to $a, the value of $a is also changed to '21'.

 

Therefore, after the code is executed, the value of $a will be '21' and the value of $b will also be '21'.

المزيد من الأسئلة المماثلة

هل تحتاج لمساعدة في كتابة سيرة ذاتية تحتوي على الكلمات الدلالية التي يبحث عنها أصحاب العمل؟