Home > other >  PHP function of multiplication
PHP function of multiplication

Time:07-23

Here is my code. This gives two separate numbers. I need to return these two numbers multiplied. Thanks for your help.

return (new CSimpleField('table','meta','_reduced_stock',null,null))->GetHtml(). ' ' .(new CSimpleField('table','product_meta','_mcmp_ppu_cust_num_of_units_override',null,null))->GetHtml();

CodePudding user response:

Use * to multiply

and intval() or floatval() to explicitly cast to number.

$a = new CSimpleField('table','meta','_reduced_stock',null,null))->GetHtml();
$b = new CSimpleField('table','product_meta','_mcmp_ppu_cust_num_of_units_override',null,null))->GetHtml();

return floatval($a) * floatval($b);

You probably don't need to explicitly convert them, but if text is a possibility, then you should. If you are using integers, use intval() instead of floatval() to avoid floating point errors.

  • Related