Jump to content

PHP math explanation


zavin

Recommended Posts

Most of my site I wrote and so I know how and why ot works. Some of the stuff on my site a gathered from other sources. I have to know what every thing does so I'm hoping someone can explain in detail exactly how the following math works. If someone could use an example to explain I would appreciate it. Thanks in advance for any help provided.

Link to comment
https://forums.phpfreaks.com/topic/150423-php-math-explanation/
Share on other sites

lol I guess it would help if I included the code I am referring to. Didn't notice it was missing until shlumph's post.

function Get_The_Level($exp) {
  $a=0;
  $end =0;
  for($x=1; ($end==0 && $x<100); $x++) {
    $a += floor($x+1500*pow(4, ($x/7)));
    if ($exp >= floor($a/4)){
} else {
  return $x;
  $end=1;
}
  }

Link to comment
https://forums.phpfreaks.com/topic/150423-php-math-explanation/#findComment-790049
Share on other sites

Well, it's already fairly straightforward, so I don't know what you want someone to explain....

 

Perhaps translate it to more math-ish terms?

 

for variables a = 0, b = 0, x = 1:

 

while end is 0 and x is less than 100:

a += greatest integer value of $x+1500*4^($x/7)

if(exp < greatest integer value of a/4)

    exit the function and return x.

 

 

 

By the way, the PHP code is not optimized.

 

function Get_The_Level($exp) {
$a=0;
for($x=1; $x < 100; ++$x) {
	$a += floor($x+1500*pow(4, ($x/7)));
	if($exp < floor($a/4)){
		return $x;
	}
}
}

 

 

Link to comment
https://forums.phpfreaks.com/topic/150423-php-math-explanation/#findComment-790092
Share on other sites

Also it's entirely pointless doing anything with variables (or, indeed, anything at all) after returning from a function. The code is entirely unreachable - the program counter's already been returned to the caller and all the local variables of the function have been popped from the stack.

 

So setting $end to 1 here is never ever ever executed:

 

     return $x;
     $end=1;

Link to comment
https://forums.phpfreaks.com/topic/150423-php-math-explanation/#findComment-790152
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.