[英]Increment a variable by 1, everytime the php script is run
I want my variable $code
to be incremented by 1 everytime, the php script is called.我希望我的变量$code
每次增加 1,调用 php 脚本。 This is my code:这是我的代码:
script.php :脚本.php :
<?php
$code = "05000"; /*On first run, the $code will be "05000",
then on second run it will be "05001" and so on and so forth*/
?>
Or in other words, I want my $code
to give a unique value (which should be self incrementing) everytime, the script is called.或者换句话说,我希望每次调用脚本时我的$code
都给出一个唯一的值(应该是自增的)。 How can I do that?我怎样才能做到这一点?
Store it in a simple file, you can use this ($count = $code for you) :将它存储在一个简单的文件中,您可以使用它($count = $code for you):
<?php
$storageFile = "storage.txt";
if (!file_exists($storageFile))
{
file_put_contents($storageFile, "0");
}
$count = file_get_contents($storageFile);
file_put_contents($storageFile, ($count + 1));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.