初学函数遇到一个小问题
Jun 23, 2016 pm 01:25 PM 定义一个可以获取指定整数数组元素和的函数并调用。
我的代码是:
function sum($str)
{
for($i=0;$i
$sum=$sum+$str[$i];
}
return $sum;
}
$a=array(7,9,8,5,3);
sum($a);
?>
啥也没输出,傻眼了
回复讨论(解决方案)
<?php function sum($str) { $sum=0; for($i=0;$i<count($str);$i++){ //$sum=0; $sum=$sum+$str[$i]; } return $sum;//你这只是返回了值,没输出, } $a=array(7,9,8,5,3); echo sum($a);?>

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

11 Best PHP URL Shortener Scripts (Free and Premium)

Working with Flash Session Data in Laravel

Build a React App With a Laravel Back End: Part 2, React

Simplified HTTP Response Mocking in Laravel Tests

cURL in PHP: How to Use the PHP cURL Extension in REST APIs

12 Best PHP Chat Scripts on CodeCanyon
