php array function (3)

WBOY
Release: 2016-08-08 09:23:06
Original
1037 people have browsed it

Six: The product and sum functions within the array array_sum($array);array_product($array);

<code><span>$arr</span> = <span>array</span>(<span>"2"</span>,<span>"3"</span>,<span>"4"</span>);
<span>$sum</span> = array_sum(<span>$arr</span>);
<span>$product</span> = array_product(<span>$arr</span>);
<span>print</span>(<span>$sum</span>.<span>"<br/>"</span>);
<span>print</span>(<span>$product</span>);</code>
Copy after login

The result is as shown below
php array function (3)

Two summation and product functions In the function, if there is a non-numeric cell in the array, this cell is counted as zero. Therefore, for the multiplication of arrays containing non-numeric units, the result is 0; as shown in the figure below


<code><span>$arr</span> = <span>array</span>(<span>"2"</span>,<span>"3"</span>,<span>"4"</span>,<span>"a"</span>);
<span>$sum</span> = array_sum(<span>$arr</span>);
<span>$product</span> = array_product(<span>$arr</span>);
<span>print</span>(<span>$sum</span>.<span>"<br/>"</span>);
<span>print</span>(<span>$product</span>);</code>
Copy after login

php array function (3)

The above introduces the PHP array function (3), including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template