ID: 23964 Updated by: [EMAIL PROTECTED] Reported By: prof_moriarty at veryfast dot biz -Status: Open +Status: Wont fix Bug Type: Feature/Change Request Operating System: Win98 se PHP Version: 4.3.2 New Comment:
can be done in user-space.. :) Previous Comments: ------------------------------------------------------------------------ [2003-06-03 12:37:56] prof_moriarty at veryfast dot biz fair point & good catch. Mind, now you've gone and re-inforced my point about us 'mere mortals'. ;) I'm assuming 'php-general is the general mailing list. ------------------------------------------------------------------------ [2003-06-03 06:36:08] [EMAIL PROTECTED] This should be on php-general by now, but... Why the inner foreach? According to the stated problem, you *know* which key you're looking for, so why not go straight for it? So... function proposed_function($array, $key) { $total = 0; foreach($array as $subarr) if (isset($subarr[$key])) $total += $subarr[$key]; return $total; } ------------------------------------------------------------------------ [2003-06-02 19:52:53] prof_moriarty at veryfast dot biz You see, if someone with a php.net e-mail addy get's it wrong, what hope do us 'mere-mortals' have?!?!?! hehe ;) ------------------------------------------------------------------------ [2003-06-02 17:47:10] [EMAIL PROTECTED] Ah, touche... good catch... ------------------------------------------------------------------------ [2003-06-02 17:43:31] prof_moriarty at veryfast dot biz sorry, i can't code in C/++, so can't do it myself. :) however that code can't work (i just tested it to make sure). You missed a layer of the looping. It should be: $total = 0; foreach($array_to_manipulate as $boxes => $box_arrays){ foreach($box_arrays as $key=> $value){ if ($key == 'height') { $total += $value; } } } That should work..... As you can see, with sizeable arrays, it could go around quite a few times... Which (from a performance front) would be better if it was done in c(++).... Hint Hint... ;) ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/23964 -- Edit this bug report at http://bugs.php.net/?id=23964&edit=1