Re: [nyphp-talk] Re: Weird Switch Behavior

2008-09-09 Thread John Campbell
Hi Mike, Maybe a simple way around this is just to use: switch("$key") It makes it pretty clear that you are only dealing with strings, and you won't have to deal with casting issues. Regards, John Campbell ___ New York PHP Community Talk Mailing List

Re: [nyphp-talk] Re: Weird Switch Behavior

2008-09-09 Thread Darryle Steplight
Hi Mike, It kind of sounds like you are talking about two different things or at least the confusion involves two different topics. Basically, if you are going to use a Switch statement it's a good practice to keep the case expression within quotation, if you want to get desired results. Also,

Re: [nyphp-talk] Re: Weird Switch Behavior

2008-09-09 Thread Ken Robinson
At 10:44 PM 9/9/2008, Michael B Allen wrote: On Tue, Sep 9, 2008 at 10:31 PM, Michael B Allen <[EMAIL PROTECTED]> wrote: > Can someone explain why the below switch matches the 0 element? > > $ cat switch.php > > $tmp = array( >'foo' => 1, >'bar' => 2, >'zap', > ); > > for

Re: [nyphp-talk] Re: Weird Switch Behavior

2008-09-09 Thread Michael B Allen
On Tue, Sep 9, 2008 at 10:56 PM, Hans Zaunere <[EMAIL PROTECTED]> wrote: >> Nevermind - $key is an int so 'foo' is being cast to an int which >> evaluates to 0. >> >> I think I would prefer that switch be a little more explicit. >> >> >switch ($key) { >> >case 'foo': >> >

Re: [nyphp-talk] Re: Weird Switch Behavior

2008-09-09 Thread Michael Southwell
Michael B Allen wrote: On Tue, Sep 9, 2008 at 10:31 PM, Michael B Allen <[EMAIL PROTECTED]> wrote: Can someone explain why the below switch matches the 0 element? $ cat switch.php 1, 'bar' => 2, 'zap', ); foreach ($tmp as $key => $val) { Nevermind - $key is an int so 'foo' is

RE: [nyphp-talk] Re: Weird Switch Behavior

2008-09-09 Thread Hans Zaunere
> > Can someone explain why the below switch matches the 0 element? > > > > $ cat switch.php > > > > > $tmp = array( > >'foo' => 1, > >'bar' => 2, > >'zap', > > ); > > > > foreach ($tmp as $key => $val) { > > Nevermind - $key is an int so 'foo' is being cast to an int whic

Re: [nyphp-talk] Re: Weird Switch Behavior

2008-09-09 Thread Darryle Steplight
Hi Michael, Switch isn't the problem. Arrays are going to behave like Arrays no matter how you choose to loop through them. $tmp = array('foo','bar','zap'); is the same as typing $tmp = array(0=>'foo', 1='bar', 2='zap'); If you don't specify the index, PHP will start using numbers starting a

[nyphp-talk] Re: Weird Switch Behavior

2008-09-09 Thread Michael B Allen
On Tue, Sep 9, 2008 at 10:31 PM, Michael B Allen <[EMAIL PROTECTED]> wrote: > Can someone explain why the below switch matches the 0 element? > > $ cat switch.php > > $tmp = array( >'foo' => 1, >'bar' => 2, >'zap', > ); > > foreach ($tmp as $key => $val) { Nevermind - $key

[nyphp-talk] Weird Switch Behavior

2008-09-09 Thread Michael B Allen
Can someone explain why the below switch matches the 0 element? $ cat switch.php 1, 'bar' => 2, 'zap', ); foreach ($tmp as $key => $val) { switch ($key) { case 'foo': case 'bar': echo "[$key][$val]\n";