How to use and change a global boolean variable inside if condition PHP | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to use and change a global boolean variable inside if condition PHP

29th Jul 2020, 9:23 PM
Mostafa Mousavi
Mostafa Mousavi - avatar
8 Answers
+ 18
if ($GLOBALS['foo'] === 2) { // do something }
30th Jul 2020, 6:14 AM
Igor Makarsky
Igor Makarsky - avatar
+ 18
Mostafa Mousavi Yes. But to be correct: $foo = 2; Using global variables is a bad practice though.
30th Jul 2020, 2:59 PM
Igor Makarsky
Igor Makarsky - avatar
+ 15
Something like this: if (true) { $GLOBALS['foo'] = 2 * $GLOBALS['foo']; } if ($GLOBALS['foo'] === 2) { // do something }
30th Jul 2020, 5:39 AM
Igor Makarsky
Igor Makarsky - avatar
30th Jul 2020, 8:23 AM
Mostafa Mousavi
Mostafa Mousavi - avatar
+ 2
Mostafa Mousavi Can you elaborate more on the question? do you have a code here in SoloLearn for a review? I would try to help if you can show me link to your code.
30th Jul 2020, 5:30 AM
Ipang
+ 1
Ipang it was a code that i m coding for a telegram bot and its huge 😅 and it dosent make sense if is paste all of it
30th Jul 2020, 2:45 PM
Mostafa Mousavi
Mostafa Mousavi - avatar
0
Igor Makarsky i meant inside if condition not changing due to condition
30th Jul 2020, 5:53 AM
Mostafa Mousavi
Mostafa Mousavi - avatar
0
Igor Makarsky another question Is declaring it for the first time like normal variables? I mean like ex : foo = 2;
30th Jul 2020, 2:42 PM
Mostafa Mousavi
Mostafa Mousavi - avatar