Jump to content

array_product alternative


giraffemedia

Recommended Posts

Ummm, not sure about function wise. Make your own.

 

function array_product($arr){

$product = 1; //start at 1
foreach($arr as $values){
$product *= $values;
}

return $product;
}

$getMultiply = array_product(array(4,6,1,7));
echo $getMultiply; //Will output 168

Link to comment
Share on other sites

I get the following error...

 

Fatal error: Cannot redeclare array_product() (previously declared in /Applications/MAMP/htdocs/database/database_files/tools/page_space_sold.php:118) in /Applications/MAMP/htdocs/database/database_files/tools/page_space_sold.php on line 118

 

I haven't declared it before then so why is this happening?

Link to comment
Share on other sites

Because it's already a function. Is that on the PHP4 server.

If it's on the PHP4 server it shouldn't be throwing you the error. If you test it on a PHP5 server it will throw you that error.

 

Call the function something else. That will fix it. array_multiple or something.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.