六:數組內的求積與求和函數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>
積的函數中,若數組內有非數字的單元,則此單元算零。 所以對於含有非數字單元的陣列求積,結果為0;如下圖所例
<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數組函數(3),包括了方面的內容,希望對PHP教程有興趣的朋友有幫助。