In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
Today, I would like to share with you how php finds the sum of squares of array elements. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article. Let's take a look at it.
Methods: 1, use "$arr as 0;" to define a variable to store the calculation results; 2, use "foreach ($swatch $v) {}" to loop through the array; 3, in the loop body, use pow () to calculate the square value of the array elements, and use the "+ =" operator to add and sum them, syntax "$s+=pow ($vMagery 2);".
Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
The method of finding the Sum of squares of Array elements by php
In php, you can use the foreach statement, the pow () function, and the "+ =" operator to find the sum of squares of array elements.
1. Define a variable assignment 0, which is used to store the calculation results.
$swarms 0
2. Iterate through the array using the foreach statement
Syntax:
Foreach ($array as $value) {statement block;}
Iterate through the given $array array, assigning the value of the current array to $value in each loop.
3. In the loop body, calculate the sum of squares of the array elements
Use pow () to calculate the square of the element and add the square with "+ =".
Implementation code:
We use calculators to calculate:
Ok, it's right.
Description:
The pow () function calculates and returns x to the y power. If you want to divide a number equally, set y to 2; cube, set y to 3.
"+ =" is an assignment operation that assigns the variable on the left of the operator plus the value of the expression on the right to the variable on the left.
These are all the contents of the article "how to find the sum of squares of array elements by php". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.