繁体   English   中英

每次运行 php 脚本时将变量加 1

[英]Increment a variable by 1, everytime the php script is run

我希望我的变量$code每次增加 1,调用 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*/
?>

或者换句话说,我希望每次调用脚本时我的$code都给出一个唯一的值(应该是自增的)。 我怎样才能做到这一点?

将它存储在一个简单的文件中,您可以使用它($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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM