Jump to content

Abhyro

New Members
  • Posts

    3
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Abhyro's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hi Is it a good practice to create an array withing a function? Also wanted to know how the variables declared within a function behave in PHP. Are these variables destroyed once the function call is over or do they still cling on to the memory allocated to them? In case they are not destroyed it appears to me that with every call that is made to the function, more and more memory would be consumed and finally the program will crash. If this is the case arrays within functions can cause big problems....if anyone can shed light on this it will be of great help....my code has an array which is created withing a function and the program is just crashing without any error msg....hence am suspecting the above mentioned behavior. Thanks Abhijeet
  2. Hi ..am new to PHP and am using it to solve some mathematical problems which require extensive computation. Following is a code to solve a problem: <?php $num =1; $n =0; $temp = 0; $count =0; $Final =0; While( $num < [color=orange]1000000)[/color] { $n = $num; while($n >1) { if(( $n % 2) == 0) { $n = $n/2; $temp++; } else { $n =3*$n +1; $temp++; } } If($temp > $count) { $count =$temp; $Final =$num; } $num++; $temp =0; } echo $Final; echo "<BR>"; echo $count; ?> I am running into "Maximum execution time of 30 seconds exceeded" error...its happening coz of the number 1 million...the code wrks fine for 100,1000,10000 and 100000...but breaks down @ 1000000.....is there any way to solve this situation...or PHP is not capable of handling huge numbers? please help...am stuck with this even though am so close to solving the prob. Thanks Abhijeet
×
×
  • 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.