PHP pow
Raise a growth factor to a power to repeat the same multiplication over several periods.
A simple example
pow
- Start with 2 and 3
- Do this Raise 2 to the third power
- Result 8
<?php
echo (pow(2.0, 3.0)), PHP_EOL;
8
Syntax
pow($factor, $periods)
Run these examples in PHP
Save one example at a time as lesson.php. Use PHP 8.2 or later.
php lesson.phpProject repeated doubling
A print job branches into additional copies at each round. Use the starting count and the number of rounds to project the final batch before reserving paper.
<?php
$factor = 2.0;
$periods = 5.0;
printf("%.3F\n", pow($factor, $periods));
32.000
Five doublings turn one seedling tray into 32 trays.
Estimate copies in a branching print run
A print center branches each master copy into several copies in every round. Project the final count from the branching factor so the operator can budget paper before starting the job.
<?php
$copies = 3.0;
$rounds = 4.0;
printf("%.3F\n", pow($copies, $rounds));
81.000
Starting with one page and tripling its copies through four rounds produces 81 pages.
Count cells after repeated subdivision
A designer starts with one square on a poster. Each round replaces every square with four smaller squares, and the design goes through three rounds.
The factor four applies three times to the starting square.
What to watch for
For exact currency, use decimal arithmetic or integer minor units and a stated rounding policy.