i am trying to store data in a text file, something like an array into a text file using php instead of storing into mysql database.
for example here are the data to
//-- short -------------------------------------------
$data = [ "a" => "A", "b" => "B", "c" => "C" ];
echo '
data - array: ';
var_dump($data);
file_put_contents('db.php', json_encode($data) );
//get
$g = json_decode(file_get_contents('db.php') , 1); // 1 Array , 0 Object
echo '
short: var_dump($g): ';
var_dump($g);
//-- long -------------------------------------------//
$data = [ "a" => "A", "b" => "B", "c" => "C" ];
echo '
data - array: ';
var_dump($data);
echo '
json_encode($data): ';
$jdata = json_encode($data);
var_dump($jdata);
echo'
';
file_put_contents('db.php', $jdata);
//get
$jg = file_get_contents('db.php');
echo ' $jg = file_get_contents(\'db.php\'); $jg : ';
var_dump($jg);
echo '
json_decode($jg , 1) //1 Array
';
$g = json_decode($jg , 1);
var_dump($g);
echo '
json_decode($jg , 0) //0 Object
';
$g = json_decode($jg , 0);
var_dump($g);