|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
Patchesadd-fronk-support (last revision 2014-07-11 15:23 UTC by rafavega at gmail dot com)Pull RequestsHistoryAllCommentsChangesGit/SVN commits
[2014-07-11 17:00 UTC] aharvey@php.net
-Status: Open
+Status: Not a bug
[2014-07-11 17:00 UTC] aharvey@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 16:00:01 2025 UTC |
Description: ------------ What this code should do, is to take the $lines array and delete the 2B value, but it doesn’t work like that, and is because it get crash when you use the $items variable in the second foreach and you already used it as a referece variable, even if you clean the $items variable with an empty array as you see in the code. Just if you change the name or the $items variable in the second foreach it works fine. Test script: --------------- $lines = array( '1' => array( '1A' ), '2' => array( '2A', '2B', '2C' ) ); foreach($lines as &$items){ foreach($items as $key => $value){ if($value=='2B') unset($items[$key]); } } $items = array(); foreach($lines as $key => $items){ print_r($items); } Expected result: ---------------- array( '1A' ) array( '2A', '2C' ) Actual result: -------------- array( '1A' ) array( '1A' )