0
私はjsonのデコードをテストするためにこのコードを作成しましたが、何らかの理由で$config['pages'][$i]['inputs'][$j]['type']
は常にradio
です。私がちょうど$config['pages'][$i]['inputs']
までするといいですが、一度入力番号を追加すると、type
は常にradio
になります。
私のコード:php:corectlyを出力していないネストされた連想配列
<?php
$configFilePath = $_SERVER["DOCUMENT_ROOT"] . "/wms/config/author_submit.json";
$configFile = fopen($configFilePath, "r") or die("Unable to open file config.json"); // open config file
$config = fread($configFile,filesize($configFilePath)) or die("unable to read config.json"); // read config file
$config = json_decode($config, true) or die('json decoding failed'); // decode config file
?>
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<form action="upload.php" method="post" enctype="multipart/form-data"> <!-- start form -->
<?php
var_dump($config);
echo "<br><br>";
for ($i=0; $i < count($config['pages']); $i++)
{
echo "page" . $i . "<br><br>";
for ($j=0; $j < count($config['pages'][$i]['inputs']); $j++)
{
echo $config['pages'][$i]['inputs'][$j]["name"] . "<br>";
if ($config['pages'][$i]['inputs'][$j]['type'] = "radio")
{
echo $i . $j . "<br>";
var_dump($config['pages'][$i]['inputs'][$j])
echo "<br><br>";
}
}
}
?>
</form>
</body>
</html>
とauthor_submit.json
{
"pages":
[
{
"name": "Page1",
"inputs":
[
{
"title": "Catagory",
"name": "catagory",
"type": "radio",
"options":
[
{
"name": "Paper",
"value": "paper"
},
{
"name": "Letter",
"value": "letter"
}
]
},
{
"title": "Title",
"name": "title",
"type": "text"
},
{
"title": "File",
"name": "file",
"type": "file",
"fileName": "?pages[0].inputs[0]"
},
{
"name": "submit",
"title": "Submit",
"type": "submit"
}
]
},
{
"name": "Page2",
"inputs":
[
{
"title": "Catagory",
"name": "catagory",
"type": "radio",
"options":
[
{
"name": "Paper",
"value": "paper"
},
{
"name": "Letter",
"value": "letter"
}
]
},
{
"title": "Title",
"name": "title",
"type": "text"
},
{
"title": "File",
"name": "file",
"type": "file",
"fileName": "?pages[0].inputs[0]"
},
{
"name": "submit",
"title": "Submit",
"type": "submit"
}
]
}
]
}