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

form help
this doesn't work. i want the form action to go the location.href of the submit button chosen.. how

db entry based on primary key
My "topics" table contains 10 entires
*--------------*
topicid topic
------

php forms and database navigatio
Hello,
I'm new to php and i'd like to post the following.
I have written code to get records f

getting most records by count
Code: [Select]<?php

$connect = mysql_connect("localhost","dam

parsing error
can anyone explain this syntax error:

Parse error: syntax error, unexpected T_IF

The e

Most basic form question ever?
Hello,

I want to use this snippet to make sure the fields in a form are ok before processing

need to add "sizes" to shopping cart
Hey guys, I am trying to figure out a way to add a "size" selector on to this bit of code.

php automatically escaping single quotes
I'm trying to test out my security a bit and I've noticed that php is escaping my single quotes. For

Procedural to OOP
John Kleijn said that to avoid writing "crappy code", we should learn OOP and common OO pr

upload photo limits
ive got a upload photo script and im just trying to make more secure currently it limits size and as

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