What is the function of dot between the ${"a"."$i"}? | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
0

What is the function of dot between the ${"a"."$i"}?

for ($i=1; $i<=10; $i++) ${"a"."$i"} = 11- $i; // i started to confuse at this line echo $a1 + $a10 - $a5; // The answer is 5 but couldn't figure why. I need an explanation, please.

3rd Aug 2017, 4:58 AM
Zareen Azara
Zareen Azara - avatar
1 Réponse
+ 12
. is the string concatenation operator. ${"a"."$i"} = $a1 when i = 1 So, $a1 = 11 - $i = 10 So, $a1, $a2, ..., $a10 => 10, 9, ..., 1 $a1 + $a10 - $a5 = 10 + 1 - 6 = 5.
3rd Aug 2017, 5:09 AM
Krishna Teja Yeluripati
Krishna Teja Yeluripati - avatar