By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,722 Members | 1,247 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,722 IT Pros & Developers. It's quick & easy.

Best method of doing simple flags

P: n/a
Hi,

Currently when I want to set a flag to detect later on in the script,
I do this:

$something_flag = 1;

then later on in the script:

if ($something_flag) {
do_something();
}

Is this the best way of doing simple yes/no tests in PHP, or is there
another way I haven't discovered yet?

Thanks,
Harry
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
*** harryman100 escribió/wrote (18 Sep 2004 06:05:55 -0700):
$something_flag = 1;

then later on in the script:

if ($something_flag) {
do_something();
}

Is this the best way of doing simple yes/no tests in PHP, or is there
another way I haven't discovered yet?


Using TRUE or FALSE instead of 1 and 0 is almost the same, but slightly
clearer. Other than that, I see nothing wrong in your method.
--
-+ Álvaro G. Vicario - Burgos, Spain
+- http://www.demogracia.com (la web de humor barnizada para la intemperie)
++ Las dudas informáticas recibidas por correo irán directas a la papelera
-+ I'm not a free help desk, please don't e-mail me your questions
--
Jul 17 '05 #2

P: n/a
On 18 Sep 2004 06:05:55 -0700, harryman100 wrote:
Hi,

Currently when I want to set a flag to detect later on in the script,
I do this:

$something_flag = 1;

then later on in the script:

if ($something_flag) {
do_something();
}

Is this the best way of doing simple yes/no tests in PHP, or is there
another way I haven't discovered yet?


Only slightly better is to use actual boolean values, i.e. $something_flag
= true;

That way there is no integer to boolean conversion.

Berislav
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.