Login or Sign Up
Logging in...
Remember me
Log in
Or
Sign Up
Forgot password or user name?
Log in with
Search in titles only
Search in PHP only
Search
Advanced Search
Forums
BYTES
Product Launch
Updates
Developer Toolkit
Today's Posts
Member List
Calendar
Home
Forum
Topic
PHP
SUM of array
Collapse
This topic is closed.
X
X
Collapse
Posts
Latest Activity
Photos
Page
of
1
Filter
Time
All Time
Today
Last Week
Last Month
Show
All
Discussions only
Photos only
Videos only
Links only
Polls only
Events only
Filtered by:
Clear All
new posts
Previous
template
Next
Maximus
#1
SUM of array
Dec 27 '05, 10:25 AM
I want to get the sum of the array key values.
ex: $key1=>10, $key2=>15, $key3=>5
I want variable $sum = 30.
any solution?
Janwillem Borleffs
#2
Dec 27 '05, 10:45 AM
Re: SUM of array
Maximus wrote:[color=blue]
> I want to get the sum of the array key values.
>
> ex: $key1=>10, $key2=>15, $key3=>5
>
> I want variable $sum = 30.
>[/color]
Kimmo already supplied the solution; with associative arrays, use it with
PHP: Manual Quick Reference
http://www.php.net/array_values:
PHP is a popular general-purpose scripting language that powers everything from your blog to the most popular websites in the world.
$array = array('key1'=10 , 'key2'=15, 'key3'=5);
$sum = array_sum(array _values($array) );
JW
Comment
Post
Cancel
Previous
template
Next
Working...
Yes
No
OK
OK
Cancel
👍
👎
☕
Comment