我是php的新手,我已经爱上了我的进步。所以我现在做的事情只是为了好玩。我有两页纸。第一页有一个到第二页的链接,如下所示:
<h2>You can click the link below to skip to the next page</h2>
<a href="page2.php?food=rice&dress=lacoste">Click Here</a>"
现在在第二页,我成功地获得了食物的值通过使用get数组,像这样
$food = $_GET['food'];
echo $food;
现在我的问题是,我如何添加一个新的项目到数组,例如鸡。这可能吗?如果是,请告诉我怎么做。谢谢大家=)
你需要让你的链接看起来像这样
<a href="page2.php?food[]=rice&food[]=chicken&dress=lacoste">Click Here</a>"
注意参数末尾的[]
。这意味着参数将作为数组传递给PHP。如果你做一个print_r($_GET['food']);
你会得到一个包含rice
和chicken
元素的数组
您可以在url中设置food=rice-chicken
,并在php中分解字符串