繁体   English   中英

PHP:嵌套的关联数组不输出corectly

[英]php: nested associative array not outputting corectly

我已经编写了这段代码来测试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")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM