이 코드를 json 디코딩을 테스트하기 위해 만들었지 만 어떤 이유로 $config['pages'][$i]['inputs'][$j]['type']
항상 radio
. 내가 할 때 $config['pages'][$i]['inputs']
괜찮지 만 입력 번호를 추가하면 type
항상 radio
.
내 코드 :
<?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"
}
]
}
]
}
같음 인수에는 두 개의 = 기호가 필요합니다.
하나만 있으면 비교하는 대신 변수를 설정할 수 있습니다.
if ($config['pages'][$i]['inputs'][$j]['type'] == "radio")
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다