I have a serialized array of values saved to a file and need to change the value of one of the variables. In the example I change the value of $two and then save the whole array back into the file with the new value.
Is there a more efficient way of altering just the single value with out having to read and write the entire file/array.
$data = file_get_contents('./userInfo');
$data = unserialize($data);
extract($data);
$two="this is a altered value";
$userData = array(
'one' => $one,
'two' => $two,
'three' => $three
);
$file=fopen("../userInfo",'w');
fwrite($file, $userData);
fclose($file);
Option 1: database row for each array entry.
Option 2: different file for each array entry, using file name instead of array key. Basically use a directory in the file system as a very simple database.
Option 3: fixed sized entries in flat file, so you can multiply the array index by the block size for read and write. You would have to truncate data bigger than your chosen block size. Basically use the single file as a very simple database.