gpt4 book ai didi

PHP session 数组值一直显示为 "Array"

转载 作者:行者123 更新时间:2023-12-04 21:52:58 24 4
gpt4 key购买 nike

当将数据从表单发送到第二页时, session 的值始终使用名称“Array”而不是预期的数字。

数据应该显示在表格中,但我得到的不是示例 1、2、3、4:数组、数组、数组。(使用二维表)

下面的代码是否是“调用”数组第二页上的存储值的正确方法?

$test1 = $_SESSION["table"][0];
$test2 = $_SESSION["table"][1];
$test3 = $_SESSION["table"][2];
$test4 = $_SESSION["table"][3];
$test5 = $_SESSION["table"][4];

这到底是什么,我该如何解决?是否需要进行某种覆盖?

最好的问候。

最佳答案

您不需要任何类型的覆盖。该脚本正在打印“Array”而不是一个值,因为您试图在屏幕上打印整个数组,而不是数组中的一个值,例如:

$some_array = array('0','1','2','3');

echo $some_array; //this will print out "Array"

echo $some_array[0]; //this will print "0"

print_r($some_array); //this will list all values within the array. Try it out!

print_r() 对于生产代码没有用,因为它很丑;但是,出于测试目的,它可以防止您在嵌套数组上费尽心机。

通过索引访问数组中的元素是完全没问题的:$some_array[2]

如果你想把它放在表格中,你可以这样做:

<table>
<tr>
for($i = 0 ; $i < count($some_array) ; $i++) {
echo '<td>'.$some_array[$i].'</td>';
}
</tr>
</table>

关于PHP session 数组值一直显示为 "Array",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2859692/

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