First root of a number


Posted on 16th Feb 2014 07:03 pm by admin

Hi,

I can't find any function in php to give me the first root of a number.
Is there any built-in function for it?

For example:
81 => 3
9 => 3
64 => 2
256 => 2

I wrote this function to get it, But it seems sqrt always return a float.

Code: <?php
function getRoot($num)
{
if (is_int(sqrt($num))) // (strpos(sqrt($num), '.'))
$num = sqrt($num);

return $num;
}
?>

Any idea?

No comments posted yet

Your Answer:

Login to answer
140 Like 6 Dislike
Previous forums Next forums
Other forums

PHP webpage & array print issue
I have this code running, and it works perfectly … however, see my bottom bit about what I see

How to change Time Zone
HI
I want to change the time zone of the server to another country.How can do that?

Thanks

question about stripslashes and real_escape_string
im cleaning up an old app that I wrote fixing some of the vulernabilities from attacks.

I hav

Typing math
I've added support for typesetting math using LaTeX on the forums.

Example:
Code: [Select]

help me, how to find text on an external html site using PHP
Would anyone know how to search an external html file for a work or phrase ?

I was thinking s

bind error during socket programming
i am kinda new to socket programming. wrote the below code for a server. but getting the bind error

Output Buffering question
Hi all,

I've been trying to wrap my head around output buffering. So far I've found tons of

Extending Exception to contain method name
I was wondering, if there's a way to extend Exception in such a way, that it would contain name of a

first few characters only
hi, does anyone know how to use PHP to take the first few words of a text and limit them? i have see

How can I Compare two xml documents?
Hi all,

I am doing a POC for my project and I am using XE database 10g version.

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash