首页 > 解决方案 > 问题将json文件转换为php中的数组

问题描述

这是来自 $_POST 的数据恢复

$list = 
array(0=>$_POST['matricule'],1=>$_POST['nom'],2=>$_POST['prenom'],3=>$_POST['dn'],4=>$_POST['tel'],5=>$_POST['mail'],6=>$_POST['sexe'],7=>$_POST['adresse']);                       
$contenu_json = json_encode($list);
fwrite($fp, $contenu_json); // "test.json"

这个示例导致 test.json :

 ["123","test","test","test","test","test","test","test"]["2","test","test","test","","","",""]

示例代码 2:

$json_source = file_get_contents("test.json");
$data = json_decode($json_source, true);
echo '$data[1]';

输出 $data[0] 是 "" :( 。我想看 "123"

My objectif is to see all data json in form like :
    <input name="id" type="text" value="<?= $data[0] ?>" >

有什么问题?

标签: phparraysjsonfile-get-contentsfwrite

解决方案


推荐阅读