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

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?

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.