|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2005-11-03 21:11 UTC] sniper@php.net
[2005-11-03 21:25 UTC] tony at marston-home dot demon dot co dot uk
[2005-11-03 21:31 UTC] derick@php.net
[2005-11-04 10:07 UTC] tony at marston-home dot demon dot co dot uk
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Dec 01 12:00:01 2025 UTC |
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.