Home  >  Article  >  Backend Development  >  php array function (3)

php array function (3)

WBOY
WBOYOriginal
2016-08-08 09:23:061038browse

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>

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>

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.

Statement:
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