<legend id='ScGSH'><style id='ScGSH'><dir id='ScGSH'><q id='ScGSH'></q></dir></style></legend>

        <tfoot id='ScGSH'></tfoot>
      1. <small id='ScGSH'></small><noframes id='ScGSH'>

        <i id='ScGSH'><tr id='ScGSH'><dt id='ScGSH'><q id='ScGSH'><span id='ScGSH'><b id='ScGSH'><form id='ScGSH'><ins id='ScGSH'></ins><ul id='ScGSH'></ul><sub id='ScGSH'></sub></form><legend id='ScGSH'></legend><bdo id='ScGSH'><pre id='ScGSH'><center id='ScGSH'></center></pre></bdo></b><th id='ScGSH'></th></span></q></dt></tr></i><div id='ScGSH'><tfoot id='ScGSH'></tfoot><dl id='ScGSH'><fieldset id='ScGSH'></fieldset></dl></div>
          <bdo id='ScGSH'></bdo><ul id='ScGSH'></ul>

        默认为 switch 语句中的第一个选项?

        default as first option in switch statement?(默认为 switch 语句中的第一个选项?)
      2. <small id='Tv1xX'></small><noframes id='Tv1xX'>

        1. <legend id='Tv1xX'><style id='Tv1xX'><dir id='Tv1xX'><q id='Tv1xX'></q></dir></style></legend>

              <tbody id='Tv1xX'></tbody>
              • <tfoot id='Tv1xX'></tfoot>
                  <bdo id='Tv1xX'></bdo><ul id='Tv1xX'></ul>
                • <i id='Tv1xX'><tr id='Tv1xX'><dt id='Tv1xX'><q id='Tv1xX'><span id='Tv1xX'><b id='Tv1xX'><form id='Tv1xX'><ins id='Tv1xX'></ins><ul id='Tv1xX'></ul><sub id='Tv1xX'></sub></form><legend id='Tv1xX'></legend><bdo id='Tv1xX'><pre id='Tv1xX'><center id='Tv1xX'></center></pre></bdo></b><th id='Tv1xX'></th></span></q></dt></tr></i><div id='Tv1xX'><tfoot id='Tv1xX'></tfoot><dl id='Tv1xX'><fieldset id='Tv1xX'></fieldset></dl></div>
                  本文介绍了默认为 switch 语句中的第一个选项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我已经测试过它并且它工作正常,但它看起来......奇怪......对我来说.我是否应该担心这是非标准形式,它将在 PHP 的未来版本中删除,或者它可能会停止工作?我总是将默认情况作为最后一种情况,从来没有作为第一种情况...

                  I've tested this and it works fine, but it looks... weird... to me. Should I be concerned that this is nonstandard form which will be dropped in a future version of PHP, or that it may stop working? I've always had a default case as the final case, never as the first case...

                  switch($kind)
                  {
                      default:
                          // The kind wasn't valid, set it to the default
                          $kind = 'kind1';
                          // and fall through:
                  
                      case 'kind1':
                          // Do some stuff for kind 1 here
                          break;
                  
                      case 'kind2':
                          // do some stuff for kind2 here
                          break;
                  
                      // [...]
                  
                      case 'kindn':
                          // do some stuff for kindn here
                          break;
                  
                  }
                  
                  // some more stuff that uses $kind here...
                  

                  (如果不太明显,我要做的是确保 $kind 是有效的,因此是默认值:case.但是 switch 也执行一些操作,然后在 switch 之后也使用 $kind.那是为什么默认:落入第一种情况,并设置 $kind)

                  (In case it's not obvious what I'm trying to do is ensure $kind is valid, hence the default: case. But the switch also performs some operations, and then $kind is used after the switch as well. That's why default: falls through to the first case, and also sets $kind)

                  建议?这是正常/有效的语法吗?

                  Suggestions? Is this normal/valid syntax?

                  推荐答案

                  这是一个不寻常的习语,当你阅读它时会引起一点停顿,嗯?"的片刻.它有效,但大多数人可能希望在最后找到默认情况:

                  It is an unusual idiom, it causes a little pause when you're reading it, a moment of "huh?". It works, but most people would probably expect to find the default case at the end:

                  switch($kind)
                  {
                      case 'kind2':
                          // do some stuff for kind2 here
                          break;
                  
                      // [...]
                  
                      case 'kindn':
                          // do some stuff for kindn here
                          break;
                  
                      case 'kind1':
                      default: 
                          // Assume kind1
                          $kind = 'kind1';
                  
                          break;
                  
                  }
                  

                  这篇关于默认为 switch 语句中的第一个选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How do I pass parameters into a PHP script through a webpage?(如何通过网页将参数传递给 PHP 脚本?)
                  PHP - include a php file and also send query parameters(PHP - 包含一个 php 文件并发送查询参数)
                  Where can I read about conditionals done with quot;?quot; and quot;:quot; (colon)?(我在哪里可以阅读有关使用“?完成的条件的信息?和“:(冒号)?)
                  Accessing arrays whitout quoting the key(在不引用键的情况下访问数组)
                  What is the name for the quot;lt;lt;lt;quot; operator?(“lt;lt;lt;的名字是什么?操作员?)
                  Weak typing in PHP: why use isset at all?(PHP 中的弱类型:为什么要使用 isset?)

                        <tbody id='jyHv0'></tbody>

                      <small id='jyHv0'></small><noframes id='jyHv0'>

                        <tfoot id='jyHv0'></tfoot>
                        <legend id='jyHv0'><style id='jyHv0'><dir id='jyHv0'><q id='jyHv0'></q></dir></style></legend>
                        • <bdo id='jyHv0'></bdo><ul id='jyHv0'></ul>
                          <i id='jyHv0'><tr id='jyHv0'><dt id='jyHv0'><q id='jyHv0'><span id='jyHv0'><b id='jyHv0'><form id='jyHv0'><ins id='jyHv0'></ins><ul id='jyHv0'></ul><sub id='jyHv0'></sub></form><legend id='jyHv0'></legend><bdo id='jyHv0'><pre id='jyHv0'><center id='jyHv0'></center></pre></bdo></b><th id='jyHv0'></th></span></q></dt></tr></i><div id='jyHv0'><tfoot id='jyHv0'></tfoot><dl id='jyHv0'><fieldset id='jyHv0'></fieldset></dl></div>