How to use nested functions in PHP

1 Answer

0 votes
function func_top_get_cost($price, $tax) {
   function nested_func_calc_tax($price, $tax) {
      return ($price * $tax) / 100;
   }
   $total = $price + nested_func_calc_tax($price, $tax);  
   return round($total, 2);
}

echo func_top_get_cost(17.50, 5) . "<br />";
echo nested_func_calc_tax(17.50, 5);
 
/*
run:

18.38
0.875

*/

 



answered Oct 13, 2016 by avibootz

Related questions

1 answer 120 views
120 views asked May 31, 2022 by avibootz
1 answer 121 views
1 answer 157 views
157 views asked Feb 12, 2021 by avibootz
1 answer 209 views
1 answer 102 views
102 views asked Sep 13, 2024 by avibootz
3 answers 263 views
2 answers 1,327 views
...