我需要为我的班级写一个程序来保持保龄球比赛的分数


I need to write a program for my class will keep score of a bowling game

我需要写一个PHP程序来保持保龄球比赛的分数。我可以处理分数的计算,这不是问题。我的问题首先是将数据放入数组。

我的想法是为每个玩家设置一个数组,如下所示:

$scores = array(
array(
    'name' => 'Player 1',
    'sheet' => '10,10,10,10,10,10,10,10,10,10,10,10'
),
array(
    'name' => 'Player 2',
    'sheet' => '10,10,10,10,10,10,10,10,10,10,10,10'
),

);

我想有一个初始表格,你可以在其中输入球员姓名,然后创建数组,然后为每个球员(数组)创建另一个表格来输入分数。

做这件事最好的方法是什么?

感谢

编辑:这行吗?

<input maxlength="30" name="players[1][player1]" size="30" type="text" />
<input maxlength="30" name="players[2][player2]" size="30" type="text" />

所以上面显示的第一个表单将创建数组和玩家名称值。下面的第二种形式会增加分数,尽管我似乎无法做到这一点。

<input maxlength="30" name="players[1][score]" size="30" type="text" />
<input maxlength="30" name="players[2][score]" size="30" type="text" />

这里有一个小例子。也许有缺陷,但它应该工作(灵感)

<h1>Bowling</h1>
<?php
if ( isset ( $_POST['next'] ) ) {
  if ( isset ( $_POST['players'] ) ) {
    $exp = explode("'n", trim($_POST['players']));
    echo "<h2>Input Score</h2>";
    echo '<form method="post" action="bowling.php">';
    foreach ( $exp as $p ) {
    if ( trim($p) != '') {
      $name = trim(htmlspecialchars($p));
      echo '<fieldset>';
      echo '<label><h3>Input "' .$name.'" score</h3></label>';
      echo '<input style="width:100%" type="text" name="score[]" placeholder="Put in the score for ' . $name . '. Just for example 1 2 3 4 5">';
      echo '<input type="hidden" name="player[]" value="'.$name.'">';
      echo '</fieldset>';
    }
    }
    echo '<input type="submit" name="next" value="Results">';
    echo '</form>';
  }
  if ( isset($_POST['score'], $_POST['player']) ) {
    echo "<h2>Results</h2>";
    $i = 0;
    $result = [];
    foreach ( $_POST['player'] as $name ) {
      $result[$name] = $_POST['score'][$i];
      $i++;
    }
    var_dump($result);
  }

} else {
?>
<form method="post" action="bowling.php">
<textarea style="width:500px; height:500px;" name="players" placeholder="One player in each line and everything will be fine"></textarea>
<input name="next" type="submit">
</form>
<?php
} ?>