PHP Save Array as a JSON File and JSON File to PHP Array
<?php
$arr=[
"user"=>"root",
"port"=>3306,
"database"=>"home"
];
// Converting to JSON and saving it in a file
file_put_contents('t.json',json_encode($arr));
// Testing , if the file is created or not
echo file_get_contents('t.json');
// {"user":"root","port":3306,"database":"home"}
// Read file and convert json to array
$a = json_decode(file_get_contents('t.json'),true);
print_r($a);
/*
Array
(
[user] => root
[port] => 3306
[database] => home
)
*/
?>
ALTERNATE TITLES