简体   繁体   English

PHP-将会话项添加到数组

[英]Php - add session items to an array

Instead of adding the from session items to an array like this 而不是像这样将from会话项添加到数组中

$itemlist[0] = $_SESSION['item1'];
$itemlist[1] = $_SESSION['item2'];
$itemlist[2] = $_SESSION['item3'];

Is there a way to add the items like this? 有没有办法添加这样的项目?

$itemlist = array();

for ($index = 0; $index <= 10; $index++){
    $itemlist[$index] = $_SESSION['item{$index +1}'];
}

echo $itemlist;

you have single quotes not double quotes. 您有单引号而不是双引号。

try to replace: 尝试替换:

$itemist[$index] = $_SESSION['item{$index +1}'];

with

$itemist[$index] = $_SESSION["item{$index +1}"];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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