ID:               35093
 Updated by:       [EMAIL PROTECTED]
 Reported By:      tony at marston-home dot demon dot co dot uk
 Status:           Bogus
 Bug Type:         Arrays related
 Operating System: Windows XP
 PHP Version:      4.4.1
 New Comment:

1. policy is to mark duplicates bogus (you should search better)
2. foreach is not the problem (key() is)
3. see bug #35084 (yes, this is the same)


Previous Comments:
------------------------------------------------------------------------

[2005-11-03 21:25:45] tony at marston-home dot demon dot co dot uk

Duplicate of what bug?

I searched the bug database before submitting this, and none of the
descriptions were anywhere near what I was experiencing. How am I
supposed to know that the source of the bug is the same if the
descriptions are different?

Your response is uninformative, and you really should introduce the
status of DUPLICATE instead of BOGUS.

------------------------------------------------------------------------

[2005-11-03 21:11:23] [EMAIL PROTECTED]

Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. 

Thank you for your interest in PHP.



------------------------------------------------------------------------

[2005-11-03 21:10:23] tony at marston-home dot demon dot co dot uk

Description:
------------
When I use foreach($array as $key => $value) on an indexed array,
afterwards the index value, when viewed with key($array) is null
instead of an integer. This means that when my code tests the array to
see if it is either indexed or associative it is given the wrong
answer.

Reproduce code:
---------------
<?php
$array[] = 'string of data';

if (is_int(key($array))) {
        echo "array is indexed\n";
} else {
        echo "array is associativ\/n";
} // if

foreach ($array as $key => $value) {
    if ($key === key($array)) {
        echo "they are the same\n";
    } else {
        echo "they are NOT the same\n";
    } // if
} // foreach

if (is_int(key($array))) {
        echo "array is indexed\n";
} else {
        echo "array is associative\n";
} // if
?>

Expected result:
----------------
The output 'array is indexed' should be produced both before and after
the foreach() statement.

Actual result:
--------------
The key of an indexed array, when viewed with key($array), is not being
reported as an integer.


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=35093&edit=1

Reply via email to