Do you need break in switch when return is used?

后端 未结 8 1812
温柔的废话
温柔的废话 2021-01-30 18:56

I was wondering if I need to use \"break\" in \"switch\" function when \"return\" is used.

function test($string)
{
  switch($string)
  {
    case \'test1\':
            


        
8条回答
  •  臣服心动
    2021-01-30 19:39

    You do not need a break, the return stops execution of the function.

    (for reference: http://php.net/manual/en/function.return.php says:

    If called from within a function, the return() statement immediately ends execution of the current function

    )

提交回复
热议问题