If tutorials available on this website are helpful for you, please whitelist this website in your ad blocker😭 or Donate to help us ❤️ pay for the web hosting to keep the website running.
array_sum() , Array के integer elements का sum return करता है।
array_sum(array $array );
array ...$arrays | required : ये Array की list है जिन्हे आप आपस में merge करना चाहते हैं।
Return Value : integer या float form में Array values का sum return करता है। और अगर Array empty है तो 0 return होता है।
File : php_array_sum.php
<?php
$a = array(2, 4, 6, 8);
echo "sum(a) = " . array_sum($a);
echo "<br>";
$b = array("a" => 1.2, "b" => 2.3, "c" => 3.4);
echo "sum(b) = " . array_sum($b);
?>
sum(a) = 20 sum(b) = 6.9
अगर कोई ऐसा Array pass करते हैं जो सभी Type (String , Boolean , Array , Class , Numeric) की values contain करता है , तो भी सिर्फ numeric values का sum return होगा। लेकिन ध्यान रहे Boolean value true, 1 treat होगी जबकि false 0 ।
$a = array('k'=>2, 'g'=>2, 'Hello', true, false, 10); echo "sum(a) = " . array_sum($a); /*Output*/ sum(a) = 15
Hi ! I'm Rahul Kumar Rajput founder of learnhindituts.com. I'm a software developer having more than 4 years of experience. I love to talk about programming as well as writing technical tutorials and blogs that can help to others. I'm here to help you navigate the coding cosmos and turn your ideas into reality, keep coding, keep learning :)
Get connected with me. :) LinkedIn Twitter Instagram Facebook