$number = array(1,2,3,4,5);
# Implode into a string using | as the separator.
$stringofnumber = implode('|', $number);
# Pass the string to a session. e.g
$_SESSION['string'] = $stringofnumber;
所以当你进入你想要使用数组的页面时,只需要爆炸你的字符串。前 :
# Required before $_SESSION can be accessed.
session_start();
# Explode back to an array using | as the needle.
$number=explode('|', $_SESSION['string']);
<?php // PHP part
session_start(); // Start the session
$_SESSION['student']=array(); // Makes the session an array
$student_name=$_POST['student_name']; //student_name form field name
$student_city=$_POST['city_id']; //city_id form field name
array_push($_SESSION['student'],$student_name,$student_city);
//print_r($_SESSION['student']);
?>
<table class="table"> <!-- HTML Part (optional) -->
<tr>
<th>Name</th>
<th>City</th>
</tr>
<tr>
<?php for($i = 0 ; $i < count($_SESSION['student']) ; $i++) {
echo '<td>'.$_SESSION['student'][$i].'</td>';
} ?>
</tr>
</table>