> > Can someone explain why the below switch matches the 0 element? > > > > $ cat switch.php > > <?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 which > evaluates to 0. > > I think I would prefer that switch be a little more explicit. > > > switch ($key) { > > case 'foo': > > case 'bar': > > echo "[$key][$val]\n"; > > break; > > } > > } > > > > $ php -f switch.php > > [foo][1] > > [bar][2] > > [0][zap]
Should switch be more explicit, or should the programmer? :) Don't depend on auto type casting... H _______________________________________________ New York PHP Community Talk Mailing List http://lists.nyphp.org/mailman/listinfo/talk NYPHPCon 2006 Presentations Online http://www.nyphpcon.com Show Your Participation in New York PHP http://www.nyphp.org/show_participation.php