删除了数组元素后数组的元素个数发生的变化,不能再以定值去访问了。
解决的方法是:
1、逆向删除,即从后往前删
2、使用foeeach循环而不用for循环

解决方案 »

  1.   

    function  Del_Selected()  
    {  
     foreach($_SESSION['sDelId'] as $key=>$value)
     {
       foreach($_SESSION['sId'] as $key1=>$value1)
       {
        if($value[$key] == $value1[$key2])
        {
         unset($GLOBALS[_SESSION]['sId'][$key1]);
        }
       }
     }
    }  这样对吗?从后往前删的算法如何实现。
      

  2.   

    function  Del_Selected()  
    {  
     for($i=count($_SESSION['sDelId'])-1;$i>=0;$i--)  
     {  
       for($x=count($_SESSION['sId'])-1;$x>=0;$x--)  
       {  
      if($_SESSION['sDelId'][$i]  ==  $_SESSION['sId'][$x])  
      {  
         unset($_SESSION['sId'][$x]  );  
           
        }  
     }  
    }  
      

  3.   

    function Remove($a_id)
    {
       foreach($_SESSION['sId'] as $key=>$value)
       {
         if($_SESSION['sId'][$key] == $a_id)
         {
          unset($GLOBALS[_SESSION]['sId'][$key]);
          unset($GLOBALS[_SESSION]['sBcount'][$key]);
          unset($GLOBALS[_SESSION]['sPrice'][$key]);
          break;
        }
      }
    return true;
    }