
October 17th, 2002
02:56 AM
Failing To Increment:
Why is the folling code failing to increment:
$file = file("2test.dat");
$fp = fopen("2test.dat","w");
$inc = ++$file[0];
fwrite($fp,$inc);
echo $file[0];
for some reason it will only work on one file. Also, I'm on windows so file permissions are not the problem
Last edited by vvuiverine, October 17th, 2002 02:59 AM (Edited 1 times)

October 17th, 2002
03:05 AM
Lost in Hollywood
Status: Offline!
i think it's supposed to be
$file[0]++
___________________
"The man who makes no mistakes does not usually make anything." - Edward J. Phelps

October 17th, 2002
04:08 AM
Neversidian
Status: Offline!
If that doesn't work, try incrementing $file[0], and then setting $inc to the new value. I don't think it matters if the ++ goes before or after the variable.
___________________
Mugging Scotty Good.
www.muggingscotty.com

October 17th, 2002
06:09 AM
$file = file("2test.dat"); <-- OK
$fp = fopen("2test.dat","w"); <-- open file, then clear any content
$inc = ++$file[0]; <-- where is this array from?? $file is not an array, it is a file pointer. it points to 2test.dat
fwrite($fp,$inc);
echo $file[0];
nevermind, i'm an idiot. i didn't see that file()
$file[0]++; should work
$inc = $file[0]++;
fwrite($fp,$inc);
echo $inc;
___________________
http://celerondude.com