Help explain quiz | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 13

Help explain quiz

pls someone explain working of this code below func myf($i = 1) { static $id = 58; $id - = $i; echo $id; } myf(); myf(1); myf(-1); answer = 10099100

1st Jun 2017, 2:12 PM
Prudhvi Raaj
Prudhvi Raaj - avatar
10 Answers
+ 4
SL is failing very much :-(
4th Jun 2017, 7:12 AM
Daniel
Daniel - avatar
+ 11
yes!
1st Jun 2017, 3:44 PM
Prudhvi Raaj
Prudhvi Raaj - avatar
+ 10
hey Michal declare Static $id = 101 and check it??
1st Jun 2017, 2:39 PM
Prudhvi Raaj
Prudhvi Raaj - avatar
1st Jun 2017, 2:47 PM
Prudhvi Raaj
Prudhvi Raaj - avatar
+ 10
yes @daniel I too don't know exactly weirdest qsn ever in SL
4th Jun 2017, 7:11 AM
Prudhvi Raaj
Prudhvi Raaj - avatar
+ 9
The answer to the above code is 575657 as u said Michal
1st Jun 2017, 2:42 PM
Prudhvi Raaj
Prudhvi Raaj - avatar
+ 5
my output (php7 ubuntu64) is: 575657 note that static variable is initialized only in first call of function: http://php.net/manual/en/language.variables.scope.php#language.variables.scope.static
1st Jun 2017, 2:29 PM
Michal
Michal - avatar
+ 5
Prudhvi our last challenge, in 4 question, could you explain me that correct answer? SL not give us an answer
4th Jun 2017, 6:42 AM
Daniel
Daniel - avatar
+ 4
Something strange but without answer is the "right answer" 8-0
4th Jun 2017, 7:01 AM
Daniel
Daniel - avatar
+ 2
101 outputs 10099100
1st Jun 2017, 2:44 PM
Michal
Michal - avatar