Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize the addition of Field values in php

Shulou Source: shulou.com Published: 2022-06-02 07:14:12 11月01日 Update

This article introduces the relevant knowledge of "how to add field values in php". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Php to achieve field value addition method: 1, use the array_column () function to return the value of a single column in the input array; 2, use the array_sum () function to return the sum of the values in the array.

This article operating environment: Windows7 system, PHP7.4 version, Dell G3 computer.

How does php add field values?

The addition (summation) of a field value in the PHP array

Use the array function: array_column () to return the value of a single column in the input array

Use the array summation function: array_sum () returns the sum of the values in the array

Array (6) {[0] = > array (1) {["pv"] = > string (4) "1.72"} [1] = > array (1) {["pv"] = > string (4) "1.88"} [2] = > array (1) {["pv"] = > string (5) "22.90"} [3] = > array (1) {[pv "] = > string (4) "2.29"} [4] = > array (1) {["pv"] = > string (4) "2.04"} [5] = > array (1) {["pv"] = > string (4) "1.81"}}

Find the sum of PV values in an array

$res = array_sum (array_column ($att,'pv')); this is the end of "how to add field values in php". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Array field function content more knowledge input utility achievement next dilemma reality situation article method case environment computer system ribbon Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Linux vpn Shulou Tech Info OPPO Reno