Current Location: Home> Function Categories> array_product

array_product

Calculate the product of all values in the array
Name:array_product
Category:Array
Programming Language:php
One-line Description:Calculates the product of all values in the array.

Example

Example 1

Calculate and return the product of the array:

 <span class="token php language-php"><span class="token delimiter important"><?php</span>
<span class="token variable">$a</span> <span class="token operator">=</span> <span class="token keyword">array</span> <span class="token punctuation">(</span> <span class="token number">5</span> <span class="token punctuation">,</span> <span class="token number">5</span> <span class="token punctuation">)</span> <span class="token punctuation">;</span>
<span class="token keyword">echo</span> <span class="token punctuation">(</span><span class="token function"></span></span><mark> <span class="token function">array_product</span> <span class="token punctuation">(</span> <span class="token variable">$a</span> <span class="token punctuation">)</span></mark><span class="token punctuation"></span> <span class="token punctuation">)</span> <span class="token punctuation">;</span>
<span class="token delimiter important">?></span>

Try it yourself

Example 2

Calculate and return the product of the array:

 <span class="token php language-php"><span class="token delimiter important"><?php</span>
<span class="token variable">$a</span> <span class="token operator">=</span> <span class="token keyword">array</span> <span class="token punctuation">(</span> <span class="token number">5</span> <span class="token punctuation">,</span> <span class="token number">5</span> <span class="token punctuation">,</span> <span class="token number">2</span> <span class="token punctuation">,</span> <span class="token number">10</span> <span class="token punctuation">)</span> <span class="token punctuation">;</span>
<span class="token keyword">echo</span> <span class="token punctuation">(</span><span class="token function"></span></span><mark> <span class="token function">array_product</span> <span class="token punctuation">(</span> <span class="token variable">$a</span> <span class="token punctuation">)</span></mark><span class="token punctuation"></span> <span class="token punctuation">)</span> <span class="token punctuation">;</span>
<span class="token delimiter important">?></span>

Try it yourself

Similar Functions
  • Sort the array and maintain index relationships asort

    asort

    Sortthearrayandmaint
  • Fill the array with the given value array_fill

    array_fill

    Fillthearraywiththeg
  • Move the inner pointer in the array one by one next

    next

    Movetheinnerpointeri
  • Check if there is a value in the array in_array

    in_array

    Checkifthereisavalue
  • Calculate the intersection of the array and compare the data using the callback function array_uintersect

    array_uintersect

    Calculatetheintersec
  • Returns the current key/value pair in the array and moves the array pointer one step forward - This function has been abandoned since PHP 7.2.0. It is strongly recommended not to use this function. each

    each

    Returnsthecurrentkey
  • Calculate the differences in arrays array_diff

    array_diff

    Calculatethedifferen
  • Get key names from associative array key

    key

    Getkeynamesfromassoc
Popular Articles