将数字存储在变量中,加 1 然后重复

Store number in variable , add 1 then repeat

我正在研究 PHP CMS,快完成了

我使用 Material Design Lite 弹出式共享菜单,这需要 html id 属性

如前。如果我 post 2 篇文章和共享菜单具有相同的 ID 号,那么当用户按下其中一篇时,将出现 2 篇文章

所以我需要 PHP 为我做这件事的代码,我不需要非常困难的脚本


只需要一个脚本即可:

1 - 使变量包含 id = 0

2 - 加 1

3 - 存储新值,id = 1

4 - 每 post

重复一次

我试过这段代码:

<?php
$id = 0;
echo $id += 1 ;
$id = $id ;
?>

提前致谢

如果你想要全局计数器,你可以将它保存到文件系统:

<?php
$idstr = file_get_contents("counter.txt");
$id = intval($idstr)+1;
file_put_contents("counter.txt", $id);
echo($id);
?>