2016-11-30 8 views
0

私は2つの数字が生成され、答えを入力するたびに互いに加算または減算される数学ゲームを作ろうとしています。私は表示する数値を得ることができますが、私は表示する演算子を取得することはできません。どうすればいい?ここに私のコードは次のとおりです。cantはPHPで演算子を表示しています

<?php 

$num1 = rand(0, 20); 
$num2 = rand(0, 20); 

$operators = array(
    "+", 
    "-", 
); 

switch ($operators[array_rand($operators)]) { 
    case "+": 
     $result = $num1 + $num2; 
     break; 
    case "-": 
     $result = $num1 - $num2; 
     break; 
} 
    echo' 
     <div class="row">     
      <div class="col-md-3 col-md-offset-1">'. $num1 .'</div> 
      <div class="col-md-3 col-md-offset-1">'. $operators .'</div> 
      <div class="col-md-3 col-md-offset-1">'. $num2 .'</div> 

     </div>   
     ' 
?> 

答えて

0
<?php 

$num1 = rand(0, 20); 
$num2 = rand(0, 20); 

$operators = array(
    "+", 
    "-", 
); 
$operator = $operators[array_rand($operators)]; 
switch ($operator) { 
    case "+": 
     $result = $num1 + $num2; 
     break; 
    case "-": 
     $result = $num1 - $num2; 
     break; 
} 
    echo' 
     <div class="row">     
      <div class="col-md-3 col-md-offset-1">'. $num1 .'</div> 
      <div class="col-md-3 col-md-offset-1">'. $operator .'</div> 
      <div class="col-md-3 col-md-offset-1">'. $num2 .'</div> 

     </div>   
     ' 
?> 
+0

はあなたに優しい先生に感謝します! – Rgoat

+0

ようこそ!投票して答えを受け入れてください! – Naga

0

PHPはこのようsomethinfしよう...

<?php 

$num1 = rand(0, 20); 
$num2 = rand(0, 20); 

$operators = array("+","-", 
); 
$operator = $operators[array_rand($operators)]; 
switch ($operator) { 
    case "+": 
     $result = $num1 + $num2; 
     break; 
    case "-": 
     $result = $num1 - $num2; 
     break; 
} 
    echo' 
     <div class="row"> 
      <div class="col-md-3 col-md-offset-1">'. $num1 .'</div> 
      <div class="col-md-3 col-md-offset-1">'. $operator.'</div> 
      <div class="col-md-3 col-md-offset-1">'. $num2 .'</div> 

     </div> 
     ' 
?> 
0
<?php 

$num1 = rand(0, 20); 
$num2 = rand(0, 20); 

$operators = array(
    "+", 
    "-", 
); 



switch ($operator=$operators[array_rand($operators)]) { 
    case "+": 
     $result = $num1 + $num2; 
     break; 
    case "-": 
     $result = $num1 - $num2; 
     break; 
} 
    echo' 
     <div class="row">     
      <div class="col-md-3 col-md-offset-1">'. $num1 .'</div> 
      <div class="col-md-3 col-md-offset-1">'. $operator .'</div> 
      <div class="col-md-3 col-md-offset-1">'. $num2 .'</div> 


     </div>   
     ' 
?> 
関連する問題