Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the addition of Field values in php

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report