JSON を使用して多次元配列を作成しました。今私の問題は、チェックボックスのグループを作成する方法です(テーブルまたは水平バーなどでそれらを区切ることができるものに)。
これは、ファイルの行の例です。
{"id": "v0", "namegroup": "Table rules create OR insert", "rule": "All classes give origin to a table.", "value": 0}
そして、これは私が配列を作成する方法です:
<?php
$file = fopen("rules.txt", "r") or exit("Unable to open file!");
$arrayRules = array();
$i = 0;
while(!feof($file))
{
$line = fgets($file);
$content = json_decode(utf8_encode($line), true);
$arrayRules[$i]['id'] = $content["id"];
$arrayRules[$i][0] = utf8_decode($content["rule"]);
$arrayRules[$i]['namegroup'] = $content["namegroup"];
$arrayRules[$i][1] = $content["value"];
$i = $i + 1;
}
fclose($file);
?>
そして、これがチェックボックスを作成する方法です:
echo "<input name=\"regra[]\" value=\"" . $arrayRules[$i]["id"] . "\" type=\"checkbox\" /> " . $arrayRules[$i][0] . "<br/> " ;
ユーザーはグループの名前と他のすべてのポイントを編集できることに注意してください。お気づきのように、私の問題はチェックボックスをエコーする方法ではなく、グループごとにチェックボックスを作成して整理するためのメカニズムです。
更新1
今のところ私はこれを持っています:
for($i=0; $i < count($arrayRules); $i++)
{
if ($arrayRules[$i]['idgroup'] == 1)
{
if ($arrayRules[$i][1] == 1)
echo "<input name=\"regra[]\" value=\"" . $arrayRules[$i]["id"] . "\" type=\"checkbox\" checked onclick=\"this.checked='checked'\"/> " . $arrayRules[$i][0] . "<br/> " ;
if ($arrayRules[$i][1] == 0)
echo "<input name=\"regra[]\" value=\"" . $arrayRules[$i]["id"] . "\" type=\"checkbox\" /> " . $arrayRules[$i][0] . "<br/> " ;
}
}
?>
問題は、inif ($arrayRules[$i]['idgroup'] == 1)
が 1 であってはならず、idgroup のファイルに新しい名前または異なる名前が見つかるたびに、チェックボックスの新しいテーブル/グループを追加または作成する変数または何かである必要があることです。