Undefined offset while accessing array element which exists

后端 未结 7 1264
日久生厌
日久生厌 2020-12-15 04:03

I have an array and PHP and when I print it out I can see the values I need to access, but when I try accessing them by their key I am getting a PHP Notice. I printed the ar

相关标签:
7条回答
  • 2020-12-15 04:31

    I've just found this bug which causes array elements to be inaccessible sometimes in PHP when the array is created by a call to unserialize.

    Create a test PHP file containing (or run from the command line) the following script:

    <?php 
    
    $a = unserialize('a:2:{s:2:"10";i:1;s:2:"01";i:2;}'); 
    
    print $a['10']."\n";
    
    $a['10'] = 3; 
    $a['01'] = 4; 
    
    print_r($a);
    
    foreach ($a as $k => $v) 
    { 
      print 'KEY: '; 
      var_dump($k); 
      print 'VAL: '; 
      var_dump($v); 
      print "\n"; 
    }
    

    If you get errors you have a version of PHP with this bug in it and I recommend upgrading to PHP 5.3

    0 讨论(0)
提交回复
热议问题