我需要你的帮助,我想从存储在文件中的json数组中提取每个值。 例如:仅获取tel_fixe值:我的代码是=>
...
$result = mysqli_query($conn,"SELECT tel_fixe,tel_mobile FROM lead");
$table=array();
while($row=mysqli_fetch_assoc($result)){
$table[] = $row;
}
file_put_contents("json_mysql/json".$date_test.".txt", json_encode($table));
$dossier_injection = 'inject_json/';
$dossier_backup = 'backup_json/';
$filenames = 'json'.$date_test.'.txt';
$filename = $dossier_injection.'json'.$date_test.'.txt';
$str = file_get_contents($filename);
$json = json_decode($str, true);
mysqli_query($conn,"insert into json_injection (nom_fichier, date_injection) values ('$filename','$date_test')");
foreach ($json as $key => $value) {
foreach ($value as $key => $val) {
if ($val <> 0 ) {
mysqli_query($conn,"insert into result (tel_fixe,tel_mobile) value (????, ??????)");
}
}
}
rename($filename, 'backup_json/OK'.$filenames);
OUTPUT ==&GT;
输出
下面的代码[{"tel_fixe":"xxxxxxxxxx","tel_mobile":"xxxxxxxxxx"},
{"tel_fixe":"xxxxxxxxxx","tel_mobile":"xxxxxxxxxx"},
{"tel_fixe":"xxxxxxxxxx","tel_mobile":"xxxxxxxxxx"},
{"tel_fixe":"xxxxxxxxxx","tel_mobile":"xxxxxxxxxx"},
{"tel_fixe":"xxxxxxxxxx","tel_mobile":"xxxxxxxxxx"},
{"tel_fixe":"xxxxxxxxxx","tel_mobile":"xxxxxxxxxx"},.....]
谢谢:)(y)