Information Technology Questions and Answers Community

Getting sum of integers

How can we get the sum of integers of a string variable containing the values 1,2,3,4,5,6,7 through PHP?

PHP         Data type        
Your Answer: 

1 Answers

It could be solved through the explode() function.

<?php

echo array_sum(explode(‘,’, $input));

?>

Answered On 04 Apr at 10:21
Edit Account
LOGIN INFORMATION
Change Settings
Email Notifications Notifications will be sent to abcd@gmail.com
Select option for your email notifications:
Mature / News Filter We'll send on email when new jobs are posted
Option 2 for email notification We'll send on email when new jobs are posted