I have this issue i am writing a array to a file but when i unset() some sub arrays it keeps the comma or when i add anther sub array to the end it add a comma.
eg:
$account_data = include('./*****/AccountData.php');
$account_data[$username]['Name'] = $name;
$account_data[$username]['Password'] = $password;
$account_data[$username]['RandID'] = $randid;
$account_data[$username]['PublicD'] = $publicdownload;
$account_data[$username]['Enabled'] = $enabled;
$account_data[$username]['Admin'] = $admin;
$configdata = "<?php\n\nreturn ".var_export($account_data, true)."; \n\n?>";
$file = fopen('./*****/AccountDataTest.php', 'w');
fwrite($file, $configdata);
fclose($file);
when i run that code to add a sun array i get this
<?php
return array (
'Ryan' => array (
'Name' => 'Ryan',
'Password' => '',
'RandID' => '',
'PublicD' => 0,
'Enabled' => 1,
'Admin' => 0,
),
'Chris' => array (
'Name' => 'Christopher',
'Password' => '',
'RandID' => '',
'PublicD' => 1,
'Enabled' => 1,
'Admin' => 1,
),
);
?>
as you can see it adds a comma and when i run my unset function the code for the AccountData.php file will look the same with out the Chris but it has the following comma at the end of Ryan.
I am not sure how I can fix this I have been googling with not much luck.
I’m not sure if I understand the problem, but you would probably save yourself a lot of headaches by using serialize and unserialize to save your data in a file.