Get the App
SLTechnology News&Howtos  ›  Development  › 

How to store 10 digits and sum an array by php

Shulou Source: shulou.com Published: 2022-05-31 18:43:03 10月03日 Update

This article mainly introduces the relevant knowledge of "php how to store 10 numbers for the array and sum". The editor shows you the operation process through an actual case. The method of operation is simple and fast, and it is practical. I hope this article "how to store 10 numbers and sum the php to the array" can help you solve the problem.

Implementation method: 1, use the array () function to declare an array and store 10 numbers, syntax "$arr=array (value 1, value 2, value 3, value 4, value 5... value 10);"; 2, use array_sum () to calculate the sum of all elements in the array, syntax "array_sum ($arr)".

Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

"storing 10 numbers and summing an array" can be seen as two parts:

Declare an array and store 10 numbers

Calculate the sum of all elements in the array

In PHP, there are two functions that implement the above two parts: the array () function and the array_sum () function.

Let's take a look at the details.

1. Declare an array and store 10 numbers using the array () function

2. Use the array_sum () function to calculate the sum of all elements in the array

$sum=array_sum ($arr); / / summation echo "sum of array elements:". $sum

This is the end of the introduction to "how php stores 10 numbers and sums an array". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Tags: Array number function element two knowledge method industry grammar part difference utility sum content practicality practice tutorial article more case Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi MariaDB Redmi Shulou Information vpn