2012-04-07 10 views
-1

Hallo Ich brauche eine dynamische Array wie folgt zu machen:Array Mathe exponentielle

Ich habe eine maximale Anzahl von 25000 und 62 als exponentieller Zahl (?).

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

Dies ist nur ein Beispiel für das, was ich brauche: Berechnen Sie die Array-Werte und finden Sie, wo die maximale Zahl passt.

Irgendwelche Ideen?

Antwort

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

Oder in einer Gesamtfunktion:

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)); 
+0

Hallo, habe ein paar Probleme mit PHP 5.2 können Sie mir helfen? – greenbandit

+0

Dies sind grundlegende mathematische Funktionen in PHP, die nicht sehr versionsabhängig sind. Was genau sind deine Probleme damit? – Wrikken

0

Sie meinen, so etwas wie das?

$max=25000; 
$exp=62; 
$result=0; 
$i=1; 
while ($result<$max) 
    { 
    $result=pow($exp,$i); 
    $i++; 
    } 
echo $i; 
echo '<br>'; 
echo $result;