Home > Backend Development > PHP Tutorial > 应该怎么取出数组中某个值到某个值之间的总和呢?

应该怎么取出数组中某个值到某个值之间的总和呢?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 20:44:07
Original
1153 people have browsed it

比如这样

<br>$a = array(11,32,54,321,26,47,312,4,45,546,87,534,54,56,);

Copy after login
Copy after login

这个数组,我想算出$a[2]到$a[10]中间所有值的总和,除了一个个赋值加过来,有更方便的方法吗?

回复内容:

比如这样

<br>$a = array(11,32,54,321,26,47,312,4,45,546,87,534,54,56,);

Copy after login
Copy after login

这个数组,我想算出$a[2]到$a[10]中间所有值的总和,除了一个个赋值加过来,有更方便的方法吗?

array_slice();取出一段你需要的数组
然后 array_sum();计算总和啊。

Related labels:
php
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template