[英]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.