-1

Hi I need to make an dynamic array like this:

I have a max number of 25000 and 62 as exponential(?) number.

Array
(
    [0] => 0  
    [1] => 3844     // 62 * 62
    [2] => 238328   // 62 * 62 * 62 <---
    [3] => 14776336 // 62 * 62 * 62 * 62
)

This is just an example of what I need: calculate the array values and find where fit the max number.

Any Ideas?

greenbandit
  • 2,267
  • 5
  • 30
  • 44

2 Answers2

1
$max =  floor(log(25000,62));
$array = array_map(function($value){return pow(62,$value);},range(0,$max);

Or, in a total function:

function getpowers($base, $maxvalue){
    $max = floor(log($maxvalue,$base));
    return array_map(function($value) use ( $base ) {return pow($base,$value);},range(0,$max));
}
var_dump(getpowers(62,25000));
Wrikken
  • 69,272
  • 8
  • 97
  • 136
0

You mean something like this?

$max=25000;
$exp=62;
$result=0;
$i=1;
while ($result<$max)
  {
  $result=pow($exp,$i);
  $i++;
  }
echo $i;
echo '<br>';
echo $result;
Juraj.Lorinc
  • 503
  • 6
  • 26