-Original Message-
From: Chris Stinemetz [mailto:chrisstinem...@gmail.com]
Sent: Thursday, August 04, 2011 11:34 PM
To: PHP General
Subject: [PHP] control structure
I have a php script with a simple condition. If it is not satisfied I
want to exit the script otherwise I want to
// This part makes no sense they are not logged in and they have a
level of 1 or 2 ?
Yes. It might not be the best approach, but I am assigning the user a
value: 1, 2, or 3 while they create an account. This will limit what
they will be able to post. For example I only want users with
You could do something like this:
$valuesarr = array($a,$b,$c,$d);
If (in_array($x,$valuesarr)) {
# do something
}
Or I guess even:
If (in_array($x,array($a,$b,$c,$d))) {
# do something
}
I don't know if your method or this method have better performance but
it's a little
Why not just use a switch?...
switch ($x) {
case $a:
case $b:
case $c:
case $d:
//do whatever you need
break;
default:
//catch any other values here
break;
}
Neil
BOOT wrote:
$x ? xxx : xxx
But it makes your code less readable IMHO and offers no tangible benefit
whatsoever.
It offers the tangible benefit of evaluating to something:
return (isset($foo) ? $foo : $bar);
$query = select * from foo
.(isset($bar) ? where bar = ${bar} :
$x ? action1 : action2;
structure...
It looked something like:
$x : action1 : action2;
I'm trying to shorten having to do the following:
if ($x) {
action1;
} else {
action 2;
}
can someone please post the syntax if they know it? I am reading the
fine documentation but can't
Hello Ahbaid,
Tuesday, March 9, 2004, 11:42:21 PM, you wrote:
AG Someone had posted a tip for using an abbreviated form of an if.. else
AG structure...
AG It looked something like:
AG $x : action1 : action2;
$x ? xxx : xxx
But it makes your code less readable IMHO and offers no tangible
Yeah, but if my code is less readable, my job security goes up ;) (Kidding)
Thanks for all your help folks,
that's what I needed.
regards
Ahbaid
Richard Davey wrote:
Hello Ahbaid,
Tuesday, March 9, 2004, 11:42:21 PM, you wrote:
AG Someone had posted a tip for using an abbreviated form of
Ahbaid Gaffoor wrote:
Yeah, but if my code is less readable, my job security goes up ;) (Kidding)
Thanks for all your help folks,
that's what I needed.
regards
Ahbaid
Richard Davey wrote:
Hello Ahbaid,
Tuesday, March 9, 2004, 11:42:21 PM, you wrote:
AG Someone had posted a tip for using
On 9 Mar 2004 Richard Davey wrote:
$x ? xxx : xxx
But it makes your code less readable IMHO and offers no tangible
benefit whatsoever.
Ah, to each his/her own I guess ... I actually find:
$value = ($condition ? $val1 : $val2);
easier to read than:
if ($condition)
In article [EMAIL PROTECTED],
[EMAIL PROTECTED] says...
yeah, i really like using cases they work well and especially if you want to
do something different for different values, i forgot about that, its a good
way to do it,
does php have case else? cuz that is a really handy thing in VB
This doesnt work as expected.
if ( $var === TEST ONE || TEST TWO || TEST THREE) {
do something;
}
It returns true on all strings. Ive tried using the or operator
and the == but these fail as well. Any Ideas?
It behaves exactly as expected. Try checking the manual section on
try
if ( $var == TEST ONE || $var == TEST TWO || $var == TEST THREE) {
do something;
}
luke
- Original Message -
From: Dan J. Rychlik [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Wednesday, September 17, 2003 9:53 AM
Subject: [PHP] Control Structure problem
This doesnt work as
Thank you guys. I truly know the level of expertise on this mailing list,
and I know that it proves invaluable.
Thank you again.
-Dan
- Original Message -
From: Luke Skywalker [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Tuesday, September 16, 2003 7:01 PM
Subject: Re: [PHP] Control
: Wednesday, September 17, 2003 10:12 AM
Subject: Re: [PHP] Control Structure problem
Thank you guys. I truly know the level of expertise on this mailing list,
and I know that it proves invaluable.
Thank you again.
-Dan
- Original Message -
From: Luke Skywalker [EMAIL PROTECTED
Dan J. Rychlik mailto:[EMAIL PROTECTED]
on Tuesday, September 16, 2003 5:12 PM said:
Thank you guys. I truly know the level of expertise on this mailing
list, and I know that it proves invaluable.
lovingjab
If by I truly know the level of expertise on this mailing list you
meant I truly
:) but i know it would be really nice in
simple logical expressions
Luke
- Original Message -
From: Chris W. Parker [EMAIL PROTECTED]
To: Dan J. Rychlik [EMAIL PROTECTED]; Luke Skywalker
[EMAIL PROTECTED]; [EMAIL PROTECTED]
Sent: Wednesday, September 17, 2003 10:18 AM
Subject: RE: [PHP] Control
* Thus wrote Chris W. Parker ([EMAIL PROTECTED]):
Dan J. Rychlik mailto:[EMAIL PROTECTED]
on Tuesday, September 16, 2003 5:12 PM said:
Thank you guys. I truly know the level of expertise on this mailing
list, and I know that it proves invaluable.
p.p.s. I totally think that the
-
From: Curt Zirzow [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Wednesday, September 17, 2003 10:49 AM
Subject: Re: [PHP] Control Structure problem
* Thus wrote Chris W. Parker ([EMAIL PROTECTED]):
Dan J. Rychlik mailto:[EMAIL PROTECTED]
on Tuesday, September 16, 2003 5:12 PM said
are you thinking of default: ?
-Original Message-
From: Luke Skywalker [mailto:[EMAIL PROTECTED]
Sent: Wednesday, 17 September 2003 10:51 AM
To: [EMAIL PROTECTED]
Subject: Re: [PHP] Control Structure problem
yeah, i really like using cases they work well and especially if you want to
do
: [PHP] Control Structure problem
are you thinking of default: ?
-Original Message-
From: Luke Skywalker [mailto:[EMAIL PROTECTED]
Sent: Wednesday, 17 September 2003 10:51 AM
To: [EMAIL PROTECTED]
Subject: Re: [PHP] Control Structure problem
yeah, i really like using cases they work
On Wed, Sep 17, 2003 at 12:49:03AM +, Curt Zirzow wrote:
:
: switch ($var) {
: case 'TEST-1': case 'TEST-2': case 'TEST-2':
: do something
: }
The switch statement doesn't do an equivalency test, does it? So while
this switch statement can be rewritten as:
if (($var
* Thus wrote Eugene Lee ([EMAIL PROTECTED]):
On Wed, Sep 17, 2003 at 12:49:03AM +, Curt Zirzow wrote:
The switch statement doesn't do an equivalency test, does it? So while
this switch statement can be rewritten as:
if (($var == 'TEST-1') || ($var == 'TEST-1') || ($var ==
On Wed, Sep 17, 2003 at 01:29:26PM +1000, Tom Rogers wrote:
: Wednesday, September 17, 2003, 11:47:45 AM, Eugene Lee wrote:
:
: EL The switch statement doesn't do an equivalency test, does it?
[...]
: EL it doesn't do:
:
: EL if (($var === 'TEST-1') ||
: EL($var === 'TEST-1')
--- Eugene Lee [EMAIL PROTECTED] wrote:
: switch (true) {
: case ($var === 'TEST-1')?true:false:
: case ($var === 'TEST-2')?true:false:
: case ($var === 'TEST-2')?true:false:
:do something
: }
Oh man, that's just sick...
Partially because it's unnecessarily
On Tue, 23 Jul 2002, Javier Montserat wrote:
So refering back, i re-wrote the original example using the switch syntax...
switch (true) {
case doStep1():
case doStep2():
case doStep3():
error();
break;
default:
valid();
}
Each case expressions is evaluated, until one of them
For steps and sequences, I always use switches. Most commonly associated with the
action variable, it would look like this:
switch($action) {
default:
// what to show if no variable exists, or is set to a value
// that is not acceptable below
break;
case add_file:
//
So refering back, i re-wrote the original example using the switch syntax...
switch (true) {
case doStep1():
case doStep2():
case doStep3():
error();
break;
default:
valid();
}
Each case expressions is evaluated, until one of them evaluates to a value
equal (==) to the switch expression
I forgot to say I deleted tabs so that the width might fit in a
typical mail reader.
Jeff Oien
This code assigns rooms to kids signing up for Sunday school
at a very large church. Each subsequent registration is put into
the next room on the list. It looks up in the MySQL database
the room
29 matches
Mail list logo