Hi
I have multiarray looking like this:
$a[1] = ("kravina", 4);
$a[2] = ("proste", 6);
$a[3] = ("blbost", 2);
and I need somehow to make SUM of the numbers (4,6,2)
I tried array_sum, but (maybe because of me) it doesn´t work ...
Any ideas?
Thx
Hi
I have multiarray looking like this:
$a[1] = ("kravina", 4);
$a[2] = ("proste", 6);
$a[3] = ("blbost", 2);
and I need somehow to make SUM of the numbers (4,6,2)
I tried array_sum, but (maybe because of me) it doesn´t work ...
Any ideas?
Thx
Go through that array and make a new array that contains only the values you want summed. Then array_sum() that.
maybe I should write this to newbie forum ... could you please explain it a little more ?
Or, now that you are going through the array, start suming instead of assigning values to the new array?
you follow?
Pd. array_sum is not ment to work on multidimensional arrays
Yes I follow the words, but I don´t know how to script "going through the array" ... I mean how to go thru just the second part of array (numbers...)
Making a new array containing the second elements of the old array.
$new_array=array()
foreach($a as $element)
{ $new_array[]=$element[1];
}
mmm ... still doesn´t work ... nothing is about to show
How about looping through and just adding the second elements together...
$total = 0;
foreach ($array as $key => $value)
{
$total = $total + $value[1];
}
print ("Total is: " . $total);
Of course my code wasn't complete.