Computing limits in PHP [duplicate] - php

This question already has answers here:
Is there something that's larger than any numbers in PHP?
(9 answers)
Closed 8 years ago.
I want to compute n^(2/3) as n approaches infinity in PHP.
What I tried:
$n = "INF";
echo pow($n, (2/3));
Desired result:
INF
Actual result:
0
Any suggestions? How to compute limits in PHP?
UPDATE:
OK, first problem solved - I just needed to remove the quotation mark.
But is this actually the way to calculate a limit? Is it interpreted as a limit?

You're passing in the string "INF" into the exponential expression, which isn't valid. Try passing in just POW:
$n = INF;
echo pow($n, (2/3));
// INF

Related

php Rounding up numbers (3628 > 3630) [duplicate]

This question already has answers here:
How to round up a number to nearest 10?
(16 answers)
Closed 6 years ago.
After converting currencies I end up with the numbers below:
3628, 5987 and 2359.
I'd like to round them up so they would appear as 3630, 5990 and 2360.
What is the best approach to accomplish this?
My idea of doing this is adding a 0. in front of the number to achieve 0.3628, then using round(0.3628, 3) so that I would get 0.363 and then finally id have to remove 0. and add another zero at the end to achieve 0.3630.
There must be a better way to do it.
Like so:
echo ceil(5987 / 10) * 10;
outputs 5990

PHP return 1 number after dot in float [duplicate]

This question already has answers here:
Show a number to two decimal places
(25 answers)
Closed 6 years ago.
I have got this php code
$Likes=1112;
$Likes=$Likes/1000;
echo $Likes."k";
This code returns me 1.112k,but my goal is to get 1.1k
Use the number_format function:
echo number_format($Likes,1)."k";
And a coding style advice: don't start your variables with an upper case letter!

Split 4 digit number into 2 variables in PHP [duplicate]

This question already has answers here:
split string after x characters
(3 answers)
Closed 7 months ago.
Using PHP...
If I have a number, for example, 0901, how can I then get 2 separate variables?
The first containing "09" and the second "01".
Thanks!
Using str_split. You can divide in half.
$number = "0901";
$arr = str_split($number, strlen($number)/2);
print $arr[0];
print $arr[1];

PHP - How can I determine the numeric sequential value of a character in the english alphabet? [duplicate]

This question already has answers here:
How to convert some character into numeric in php?
(6 answers)
Closed 9 years ago.
Without using a loop, is there a way (function) to convert, for example, the letter "c" to its numeric sequence in the alphabet (3)?
I'm trying to take a literal string - $var = "c" and apply a function to it that returns 3.
Are there any built-in PHP functions that do this? I can't find any online and would rather avoid writing the function if necessary.
Anyone know of such a conversion function?
Yup.
$alphabet_position = ord(strtoupper($character)) - ord('A');

Generate the set of all X-digit numbers [duplicate]

This question already has answers here:
How to pad single-digit numbers with a leading 0
(7 answers)
Closed 11 months ago.
Basically, I need to generate a list of all seven-digit numbers (for example, 1461979) from 0000000 to 9999999. I know there are 10^7 of them (ten million), but I can't think of an efficient function to output them. I'm sure there's a generic function out there that can do it - preferably in PHP, but I can port it if need be.
Loop from 0 to 9999999 and use one of the dozens of methods for zero-filling a number, such as printf("%07d", $val).
for ($i=0; $i<=9999999; $i++) {
echo sprintf("%07d", $i) . '<br / >';
}
This might break your browser though ;)

Categories