課題用に PHP で構築された「あなたは何のキャラクターですか」クイズ Web サイトがあります。また、考えられる 5 つの文字のそれぞれを取得した人数を保存する必要もあります。
テキストだけを含むテキスト ファイルがあります0 0 0 0 0
。各 0 は、誰かが特定の文字を選択した回数のカウンターです。
それを配列に分解します
$txt = "results2.txt";
$scores = file_get_contents($txt);
$editablescores = explode(",", $scores);
次に、誰かが受け取るスコアに応じて、配列内の適切な 0 に +1 を追加します。
これは私が使用しているものの例ですが、機能しません。以下のエラーが出ます。Notice: 未定義のオフセット: /Users/sinclaa3/Sites/PHPStyles/hi.php の 53 行目に 4
0 0 0 0 0 と表示されますが、そのまま 1 が加算されます。0 0 0 0 0 1
if ($score < 6 ) {
$editablescores[0]++;
//0 denotes the position in the array that I want to add one to
};
$storablescores = implode(",", $editablescores);
file_put_contents($txt, $storablescores);