Bug #77169 [Opn->Nab]: Sorting referenced array messes last index
| From: | requinix@php.net | Date: | Sat, 17 Nov 2018 22:43:08 +0000 |
| Subject: | Bug #77169 [Opn->Nab]: Sorting referenced array messes last index | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-218001@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=77169&edit=1
ID: 77169
Updated by: requinix@php.net
Reported by: dropapapa at gmail dot com
Summary: Sorting referenced array messes last index
-Status: Open
+Status: Not a bug
Type: Bug
Package: Arrays related
Operating System: Any
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
http://php.net/manual/en/control-structures.foreach.php
Big red warning.
Previous Comments:
------------------------------------------------------------------------
[2018-11-17 22:22:10] dropapapa at gmail dot com
Description:
------------
When foreaching array of arrays referenced, the last index will remain pointer to the second last
index afterwards.
Test script:
---------------
<?php
$arrays = [
[1,3,2],
[2,8,3],
[10,8,9],
];
foreach ($arrays as &$array) {
echo 'First: ' . implode(', ', $array) . PHP_EOL;
}
$arrays[1] = [3,3,3];
foreach ($arrays as $array) {
echo 'Second: ' . implode(', ', $array) . PHP_EOL;
}
Expected result:
----------------
Last index would act same way the others do.
Actual result:
--------------
Last index is now reference to second last index.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=77169&edit=1