|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2008-01-29 00:11 UTC] tony2001@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Sat Jan 03 01:00:02 2026 UTC |
Description: ------------ Last element or $data refers to the first $prod from the Product loop, memory reference problem just thought I?d make you aware of it because I have been staring at my code for 30 min. Reproduce code: --------------- foreach( $data as &$group ) { foreach( $group as $prodId=>&$prod ) { if( !isset( $prod['Usage'] ) ) $prod['Usage'] = 0; if( !isset( $prod['Owned'] ) ) $prod['Owned'] = 0; $prod['Diff'] = $prod['Usage'] - $prod['Owned']; $heading[$prodId] = ''; } } foreach( Product::FindByCd( "Product", array_keys($heading) ) as $prod ) $heading[$prod->ProductID] = $prod->ProductName; Expected result: ---------------- [148] => Array ( [Owned] => 6 [Usage] => 4 [Diff] => -2 ) [102] => Array ( [Owned] => 5 [Usage] => 3 [Diff] => -2 ) [126] => Array ( [Usage] => 1 [Owned] => 0 [Diff] => 1 ) ) Actual result: -------------- [148] => Array ( [Owned] => 6 [Usage] => 4 [Diff] => -2 ) [102] => Array ( [Owned] => 5 [Usage] => 3 [Diff] => -2 ) [126] => Product Object ( [ProductID] => 148 [CallTypeID] => 1 [ProductSaleTypeID] => [ProductName] => 9242 [ProductDscrpn] => DUAL TUNER HD PVR [BEVArticleNo] => 64300 [R00ReqdIndcr] => 1 [ProductValue] => 0.00 [ProductActiveIndcr] => 1 [DDPriority] => 1 [SubArticleNo] => [CurrentInventoryIndcr] => 1 [TunerNo] => 2 [HDIndcr] => 0 [DishIncludedIndcr] => 0 [Duration] => [RuleName] => 9200 [InstallerVuPriority] => ) )