gpt4 book ai didi

点击 PHP "continue"

转载 作者:行者123 更新时间:2023-12-01 03:12:31 27 4
gpt4 key购买 nike

我在数组中有一些值。首先,我想在 View 中显示该数组的前两个值,接下来我想在某些按钮单击操作后显示剩余的值,并将数组索引增加 1。例如:一次点击显示第三个值,然后另一次点击显示第四个值。

我怎样才能实现这个目标?

$array=[1,2,3,4,5,6,7,8,9];
foreach($array as $a)
{
if($a>2)
continue;
echo $a.'<br/>';
}

我第一次想要这样的 View

1
2

点击按钮后我需要显示3 然后 4 然后 5 。 。 .

最佳答案

这不是 PHP 的工作方式。

PHP 脚本在服务器上运行来构建您的网页。获得后,您需要根据新参数(通过 GET 或 POST 接收)再次询问服务器来重建页面。

看起来像这样:

<?php

$array=array(1,2,3,4,5,6,7,8,9); //That is how you declare an array in PHP

if(empty($_GET["count"])){ //It's the first time on the page, show the first two elements
echo $array[0] . ' ' . $array[1];
echo '<br><a href="page.php?count=1">Next</a>'; //Send to the same page, but now send the count by GET
}

else{ //It's not the first time on the page, keep track of how many times the link was clicked
$count = $_GET["count"];
echo $array[$count] . ' ' . $array[$count+1];
$count++;
echo '<br><a href="page.php?count=' . $count . '">Next</a>';
}

?>

但是你不应该做这样的事情。如果您想与用户交互,在页面构建后动态地更改页面,您需要寻找 Javascript

关于点击 PHP "continue",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24422908/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com