在A面,我写了<?
session_start();
?>
<?
$j=0;
for($i=0;$i<100;$i++){$_SESSION[$i]=$j;
$j++;
?>然后B面写了
<?
session_start();
?>
<?
$i=0;
for($j=0;$j<100;$j++)
{ $p['$j']=$_SESSION[$i];
$i++;
echo $p['$j'];
echo "<br>";
}
?>为什么运行B的时候就会报错Notice: Undefined offset: 0 in d:\usr\www\html\untitled-2.php on line 16
Notice: Undefined offset: 1 in d:\usr\www\html\untitled-2.php on line 16
Notice: Undefined offset: 2 in d:\usr\www\html\untitled-2.php on line 16
Notice: Undefined offset: 3 in d:\usr\www\html\untitled-2.php on line 16





Notice: Undefined offset: 3 in d:\usr\www\html\untitled-2.php on line 99
这是为什么啊$_session[$i]的数组不是明明A面已经定义赋值了么。。

解决方案 »

  1.   

    这个是提示 不是错误 你在前面做一个变量判断 if isset()
      

  2.   

    当前脚本中加上: error_reporting(E_ALL & ~NOTICE); 
      

  3.   

    请贴出真实的代码!
    在你贴出的代码中,不可能出现大于 1 的下标,所以也不会有形如 Notice: Undefined offset: 2 in... 的错误信息$i=0;
    for($j=0;$j<100;$j++)
    { $p['$j']=$_SESSION[$i];
    $i++;
    echo $p['$j'];
      

  4.   

    指出你几个问题吧:
    1:$_SESSION数组不要使用整数作为他的key,至于原因见手册下面的评论
    Careful not to try to use integer as a key to the $_SESSION array (such as $_SESSION[0] = 1;)  or you will get the error "Notice: Unknown: Skipping numeric key 0. in Unknown on line 0"
    2.你第一段代码的for循环少了个大括号(很奇怪你执行不报错吗?)
    3.第二段代码$p['$j']的写法你最终得到的数组是Array ([$j] => XX )而不会是你想要的Array ( [0] => XX,[1] => xx,..... )
    然后自己去调试吧
      

  5.   

    你的代码根本不能实现你想要的功能,我试了,我是用一下方式实现的。
    A:<?php
    session_start();
    ?>
    <?php
    for($i=0; $i<100; $i++) {
    $arr[$i]=$i;
    }
    $_SESSION['arr']=$arr;
    ?>
    B:<?php
    session_start();
    ?>
    <?php
    for($i=0; $i<100; $i++) {
    $p[$i]=$_SESSION['arr'][$i];
    echo($p[$i].'<br>');
    }?>