add value to serialized array?
| From: | Bas Jobsen | Date: | Tue, 05 Feb 2002 11:24:10 +0000 |
| Subject: | add value to serialized array? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-83580@lists.php.net to get a copy of this message | ||
Hi,
At start test.txt contains a serialized array with value "one" and "two".
a:2:{i:0;s:3:"one";i:1;s:3:"two";}
after one run this is:
a:3:{i:0;s:3:"one";i:1;s:3:"two";i:2;s:4:"tree";}
But the last row prints nothing. Why?
Tnx,
Bas
<?
$array=array();
$fp=fopen("test.txt","r");
flock($fp,1);
$array=unserialize(fread($fp,filesize("test.txt")));
flock($fp,3);
fclose($fp);
array_push($array,"tree");
$fp=fopen("test.txt","w+");
flock($fp,2);
fwrite($fp,serialize($array));
flock($fp,3);
fclose($fp);
$fp=fopen("test.txt","r");
flock($fp,1);
$array=unserialize(fread($fp,filesize("test.txt")));
flock($fp,3);
fclose($fp);
echo $array[0].$array[1].$array[2];
?>