PHP会话数组值一直显示为"数组"

Ner*_*has 2 php

将数据从表单发送到第二页时,会话的值始终使用名称"Array"来保证预期的数字.

数据应该显示在一个表中,但是示例1,2,3,4的输入我得到:Array,Array,Array.(使用二维表)

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

$test1 = $_SESSION["table"][0];
$test2 = $_SESSION["table"][1];
$test3 = $_SESSION["table"][2];
$test4 = $_SESSION["table"][3];
$test5 = $_SESSION["table"][4];
Run Code Online (Sandbox Code Playgroud)

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

最好的祝福.

jor*_*ens 7

您不需要任何覆盖.该脚本正在打印"数组"而不是值,因为您尝试在屏幕上打印整个数组,而不是数组中的值,例如:

$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!
Run Code Online (Sandbox Code Playgroud)

print_r()对生产代码没用,因为它很难看; 但是,出于测试目的,它可以防止您将头发拉出嵌套数组.

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

如果你想在表中你可能会做这样的事情:

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


小智 6

如上所述,试试吧

echo "<pre>";
print_r($_SESSION);
echo "</pre>";
Run Code Online (Sandbox Code Playgroud)

这应该会显示会话数组中的内容.