Definition and UsageThe sqrt() function returns square root of a positive float number. Since square root for negative number is not defined, it returns NAN. This is one of the most commonly used functions.This function always returns a floating point number.Syntaxsqrt ( float $arg ) : floatParametersSr.NoParameter & Description1arga number whose square root is to be obtainedReturn ValuesPHP sqrt() function returns square root of the given arg number. For negative number, the function returns NAN.PHP VersionThis function is available in PHP versions 4.x, PHP 5.x as well as PHP 7.x.Example Live DemoFollowing example calculate square root of 100−OutputThis will produce following ... Read More
Definition and UsageThe sinh() function calculates hyperbolic sine of given angle in radians. A hyperbolic sine function is defined assinh(x) = (ex – e-x))/2This function returns a float value between Π and -Π.Syntaxsinh( float $arg ) : floatParametersSr.NoParameter & Description1argA floating point value that represents angle in radiansReturn ValuesPHP sinh() function returns hyperbolic sine ratio of given parameter.PHP VersionThis function is available in PHP versions 4.x, PHP 5.x as well as PHP 7.x.Example Live DemoFollowing example calculates sinh(pi/2) and returns 2.3012989023073 which is also the result of formula (ex – e-x))/2−OutputThis will produce following result −sinh(M_PI_2) = 2.3012989023073 using formula = ... Read More
Convert dd/mm/yyyy string to Unix timestamp with the help of UNIX_TIMESTAMP(). The syntax is as follows −SELECT UNIX_TIMESTAMP(STR_TO_DATE(yourColumnName, '%d/%m/%Y')) as anyVariableName FROM yourTableName;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table ConvertddmmyyyyInUnixTimeStamp -> ( -> Id int NOT NULL AUTO_INCREMENT, -> Created_at varchar(30), -> PRIMARY KEY(Id) -> ); Query OK, 0 rows affected (0.57 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into ConvertddmmyyyyInUnixTimeStamp(Created_at) values('10/11/2012'); Query OK, 1 row affected (0.21 sec) mysql> ... Read More
Get hash value of each row using MD5() function from MySQL. The syntax is as follows −SELECT MD5(CONCAT(yourColumnName1, yourColumnName2, yourColumnName3, .......N)) as anyVariableName FROM yourTableName;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table getHashValueForEachRow -> ( -> Id int NOT NULL AUTO_INCREMENT, -> Name varchar(20), -> Age int, -> Marks int, -> PRIMARY KEY(Id) -> ); Query OK, 0 rows affected (1.25 sec)Insert records in the table using insert command. The query is as follows −mysql> insert into getHashValueForEachRow(Name, Age, ... Read More
Definition and UsageThe sin() function returns the sine ratio of given angle in radians. In trigonometry, sine of an angle is defined as ratio of lengths of opposite side and hypotenuse.sin(x) = opposite/hypotenuseIf x=90 degree, sin(x) = 1 as opposite side of right angle is a hypotenuseThis function returns a float value.Syntaxsin ( float $arg ) : floatParametersSr.NoParameter & Description1argA floating point value that represents angle in radiansReturn ValuesPHP sin() function returns sine ratio of given parameter.PHP VersionThis function is available in PHP versions 4.x, PHP 5.x as well as PHP 7.x.Example Live DemoFollowing example calculates sin(pi/2) and returns 1. Sine ratio of 90 deg is ... Read More
You can use CASE statement in MySQL to map keys to values for an individual field in select query. The syntax is as follows −SELECT yourColumnName1, yourColumnName2, yourColumnName3, .........N ( CASE WHEN yourColumnName = 1 THEN 'ENABLED' ELSE 'DISABLED' END ) AS anyVariableName FROM yourTableName;You can use IF() function also for the same purpose. The syntax is as follows −SELECT yourColumnName1, yourColumnName2, yourColumnName3, .........N ,IF(yourColumnName, 'ENABLED', 'DISABLED') as anyVariableName FROM yourTableName;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table MapKeys -> ( ... Read More
Definition and UsageThe round() function proves useful in rounding any floating point number upto a desired precision level. Positive precision parameter causes the number to be rounded after decimal point, whereas with negative precision, rounding occurs before decimal point. Precision is 0 by default.For example, round(10.6) returns 11, round(10.2) returns 10. The function always returns a floating point number.This function also has another optional parameter called mode takes one of the redefined constants described later.Syntaxround ( float $value , int $precision , int $mode ) : floatParametersSr.NoParameter & Description1valueA float number to be rounded2precisionnumber of decimal digits to round to. ... Read More
To MySQL order string with numbers, the following is the syntax, wherein we have used ORDER BY, SUBSTR() and CAST() −SELECT *FROM yourTableName ORDER BY SUBSTR(yourColumnName FROM 1 FOR 2), CAST(SUBSTR(yourColumnName FROM 2) AS UNSIGNED);To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table OrderByStringWithNumbers -> ( -> Id int NOT NULL AUTO_INCREMENT, -> Words varchar(10), -> PRIMARY KEY(Id) -> ); Query OK, 0 rows affected (0.86 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert ... Read More
Definition and UsageMost trigonometric functions like sin, cos, tan etc require angle argument in radians. Whereas, in practice angle is represented in degrees. The rad2deg() function proves useful in conversion of radian angle to degrees.This function returns a float number such that number=rad2deg(x) where x is angle in radians. angle in radian = angle in deg *180/piFor example rad2deg(Π) is equal to 180 degreesSyntaxrad2deg ( float $number ) : floatParametersSr.NoParameter & Description1numberA float number reprsenting angle in radiansReturn ValuesPHP rad2deg() function returns a float number that represents angle in degrees.PHP VersionThis function is available in PHP versions 4.x, PHP 5.x ... Read More
Definition and UsageThe pow () function is used to compute power of a certain number. It returns xy calculation, also termed as x raised to y. PHP also provides "**" asexponentiation operator.So, pow(x, y) returns xy which is same as x**ySyntaxpow ( number $base , number $exp ) : numberParametersSr.NoParameter & Description1baseThe base to be raised2exppower to which base needs to be raisedReturn ValuesPHP pow() function returns base raised to power of exp. If both arguments are non-negative integers, the result is returned as integer, otherwise it is returned as a float.PHP VersionThis function is available in PHP versions 4.x, PHP 5.x ... Read More