reset array pointer weird behavior

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • guillermobytes
    New Member
    • Jan 2010
    • 77

    #1

    reset array pointer weird behavior

    Hi everyone,

    I need some help here with a situation where I have an array and a call to reset() or even when assigning that array to another variable the internal pointer does not point to the first element!!!

    I don't know how to debug this..

    the array is an object attribute and it is set from a preg_match_all( ) call.

    i'm sure there are elements in the array... I don't understand :(

    here is a debug result :
    Code:
    preg_match_all($regex, $input, $this->_matches, PREG_SET_ORDER);
    reset($this->_matches);
    $a = $this->_matches;
    output content of $this->_matches :
    Code:
    print_r($this->_matches);
    Array
    (
        [0] => Array
            (
                [0] => <a href="index.php?lien=acteur&nom=Erin Kelly">Erin Kelly</a>, 
                [1] => Erin Kelly
            )
     
        [1] => Array
            (
                [0] => <a href="index.php?lien=acteur&nom=Diane Gaidry">Diane Gaidry</a>, 
                [1] => Diane Gaidry
            )
     
        [2] => Array
            (
                [0] => <a href="index.php?lien=acteur&nom=Kevin McCarthy">Kevin McCarthy</a>, 
                [1] => Kevin McCarthy
            )
     
    )
    trying to get first element :
    Code:
    (list($key, $this->_currentMatch) = each($this->_currentMatches));
    output $this->_currentMatc h //supposedly first array element... but actually last element!
    Code:
    print_r($this->_currentMatch);
    Array
    (
        [0] => <a href="index.php?lien=acteur&nom=Kevin McCarthy">Kevin McCarthy</a>, 
        [1] => Kevin McCarthy
    )
    if you have any suggestions they are very very wellcome

    Thank you very much!
  • JKing
    Recognized Expert Top Contributor
    • Jun 2007
    • 1206

    #2
    Are you using a loop anywhere in your code?

    Comment

    Working...