php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #11938 Bug in array handling
Submitted: 2001-07-06 14:54 UTC Modified: 2001-07-06 14:59 UTC
From: phil3k at aon dot at Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 4.0.5 OS: Windows 98
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: phil3k at aon dot at
New email:
PHP Version: OS:

 

 [2001-07-06 14:54 UTC] phil3k at aon dot at
<?php
	
    //Two elements in an Array
    $array[] = "Maria";
    $array[] = "Lisa";
	
    //just a test output
    array_walk ($array, "my_print");


    //and then free the first element of the array
    unset ($array[0]);

    function my_print ($value)
    {
	print $value . " ";
    }
	
    print "<br />";
    //The following dump will produce:
    //array(1) { [1]=> string(4) "Lisa" } 
    //This means that the first element has the index 1 
    //But it should have index 0
    var_dump ($array);
?>

If you have more than two elements, and you free one of them, you can just prevent this bug, by resorting the array with any sort function. But with only two elements, this won't work, and if you clear the first of these, you will get the same result as I have got, there was one element,  but with the wrong index.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-07-06 14:59 UTC] kalowsky@php.net
Bug submitted twice...
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 17:01:29 2024 UTC