2016-07-12 4 views
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" 
       } 
      ] 
     } 
    ] 
} 

ответ

0

равный аргументу необходимо два = знаки.
, имея только один, задает переменную вместо сравнения.

if ($config['pages'][$i]['inputs'][$j]['type'] == "radio") 
Смежные вопросы