具有功能的Php开关盒不起作用

时间:2014-03-20 09:16:35

标签: php switch-statement

为什么第一个逻辑工作

<!DOCTYPE html>
<html>
<head>
<title>Installation Script</title>
</head>
<?php
$step = (isset($_GET['step']) && $_GET['step'] != '') ? $_GET['step'] : '';
switch($step){
  case '1':
  step_1();
  break;
  case '2':
  step_2();
  break;
  case '3':
  step_3();
  break;
  default:
  step_1();
}
?>
<body>

<?php
function step_1(){ 
 some php code for the below form
?>
  form (html code)
<?php 
}

function step_2(){
 some php code for the below form
  ?>
  form (html code)
<?php
}

function step_3(){
 some php code for the below form
?>
form (html code)
<?php
}
?></body>
</html>

但第二个没有?

<?php
$result='';
$step = (isset($_GET['step']) && $_GET['step'] != '') ? $_GET['step'] : '';
switch($step){
  case '1':
  step_1();
  break;
  case '2':
  step_2();
  break;
  case '3':
  step_3();
  break;
  default:
  step_1();
}


function step_1(){ 
$result='';
 some php code for the $result form in this function
 $result.='html form';
}

function step_2(){ 
$result='';
 some php code for the $result form in this function
 $result.='html form';
}

function step_3(){ 
$result='';
 some php code for the $result form in this function
 $result.='html form';
}
?><!DOCTYPE html>
<html>
<head>
<meta charset="utf8" />
<title>Install</title>
</head>

<body>
<div id="wrapper">
<header id="header">
    <h1>Installer</h1>
</header>

<section>
    <?php print $result; ?>
</section>

<footer id="footer">
</footer>
</div>
</body>
</html>

没关系,我不应该使用像这样的安装程序,我不会,但我只有这段代码向您展示我的问题。在我看来,第二个例子的结构比第一个例子更合乎逻辑,但它不起作用。你能帮助我吗?或者在哪里可以找到关于此的一些信息?

0 个答案:

没有答案