ID: 23964 Updated by: [EMAIL PROTECTED] Reported By: prof_moriarty at veryfast dot biz Status: Open Bug Type: Feature/Change Request Operating System: Win98 se PHP Version: 4.3.2 New Comment:
Perhaps someone else will be motivated enough to implement this (feel free to write it yourself and submit a patch to [EMAIL PROTECTED]) but here's some userspace code which accomplishes what you want. $total = 0; foreach($array_to_manipulate as $key => $value) if ($key == 'height') $total += $value; Which I'm sure you can see is easy enough to wrap in a function. Previous Comments: ------------------------------------------------------------------------ [2003-06-02 15:55:40] prof_moriarty at veryfast dot biz This is tricky to explain, but easy to understand. At present there's a function: array_sum that adds up all the values in an array. I would like to suggest somthing similar, and at the same time intrinsically different. The ability to sum up an elements value in a multi-dimensional array. Example multi-dim-array: array ( 'box1' => array ( 'height' => 5, 'length' => 10, 'width' => 3.5, ), 'box2' => array ( 'height' => 17, 'length' => 9, 'width' => 8, ), ) The above array contains two boxes and a few dimensions... What do i do if i want to work out the combined height of the boxes (to see if they can fit into a space)? I could write a little function to do it sure. But i figure quite a few other people could use this little function too, so i'll suggest it to you. some clarification, using the above example array. the syntax for the function could be: mixed proposed_function(array input, string element_name) An example of it in use: $result = proposed_function($array_to_manipulate, 'height'); echo $result; The result would be: 22 //becase 5 + 17 = 22 :) I hope thats clear... Keep up the good work folks... :) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=23964&edit=1