SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Pandora Tipem's Avatar
    Join Date
    Feb 2006
    Posts
    450
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Add all digits of a number together function?

    Hey,

    How could I add all of the digits of a number together through a function (e.g., 408 would become 4+0+8 = 12, so the output of the function would be 12)? I've never had to do anything like that before in PHP...

    Thanks for the help!!
    Tipem
    Tipem no fancy sig, yup
    Need Neopets Help? Try Neopets
    fun adoptable eggs

  2. #2
    hi galen's Avatar
    Join Date
    Jan 2006
    Location
    New Haven, CT
    Posts
    1,228
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    array_sum(str_split(number))

  3. #3
    Pandora Tipem's Avatar
    Join Date
    Feb 2006
    Posts
    450
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks! It works great!
    Tipem no fancy sig, yup
    Need Neopets Help? Try Neopets
    fun adoptable eggs


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •