mt_rand Function in PHP

karthikeya Boyini
Updated on 27-Dec-2019 06:56:17

106 Views

The mt_rand() function is used to generate random numbers. The numbers are generated using the Mersenne Twister algorithm.Note − This function is faster than the rand() functionSyntaxmt_rand() or mt_rand(min, max)Parametersmin − Default is 0.The lowest number to be Returned.max − The highest number to be Returned.ReturnThe mt_rand() function Returns a random integer between min (or 0) and max. FALSE is Returned if max < min.Example Live DemoOutput144ExampleLet us see another example − Live DemoOutput132850920

Min Function in PHP

karthikeya Boyini
Updated on 27-Dec-2019 06:55:31

133 Views

The min() function Returns the minimum value of an array.Syntaxmin(arr_values); or min(val1,val2,...);Parametersarr_values − The array with values.val1, val2 − The values to compare.ReturnThe min() function Returns the minimum value of an array.Example Live DemoOutput12ExampleLet us see another example − Live DemoOutput12

Max Function in PHP

Samual Sam
Updated on 27-Dec-2019 06:53:28

168 Views

The max() function Returns the maximum value of an array.Syntaxmax(arr_values); or max(val1,val2,...);Parametersarr_values − The array with values.val1, val2 − The values to compare.ReturnThe max() function Returns the maximum value of an array.Example Live DemoOutput89ExampleLet us see another example − Live DemoOutput89

Log1p Function in PHP

karthikeya Boyini
Updated on 27-Dec-2019 06:52:28

124 Views

The log1p() function Returns log(1+number), computed in a way that is accurate even when the value of number is close to zero.Syntaxlog1p(val)Parametersval − The specified numberReturnThe log1p() function Returns log(1+number), computed in a way that is accurate even when the value of number is close to zero.Example Live DemoOutput0.69314718055995ExampleLet us see another example − Live DemoOutput0ExampleLet us see another example − Live DemoOutput2.39789527279841.3083328196502

Allow Regex Match in MySQL SELECT Statement

AmitDiwan
Updated on 27-Dec-2019 06:51:28

176 Views

Yes, we can do regex match in a select statement −select yourColumnName from yourTableName where yourColumnName regexp '^yourValue';Let us first create a table −mysql> create table DemoTable1892    (    FirstName varchar(20)    ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1892 values('John'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1892 values('Adam'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1892 values('Jace'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1892 values('Johny'); Query OK, 1 row affected (0.00 sec) mysql> insert into ... Read More

log10 Function in PHP

Samual Sam
Updated on 27-Dec-2019 06:51:22

94 Views

The log10() function Return the base-10 logarithm of a number.Syntaxlog10(num)Parametersnum − The value to calculate the logarithm for.ReturnThe log10() function Returns base 10 logarithm of a number.Example Live DemoOutput0ExampleLet us see another example − Live DemoOutput-INFExampleLet us see another example − Live DemoOutput10.43136376415899

MySQL Stored Procedure to Declare Two Values and Perform Mathematical Operation

AmitDiwan
Updated on 27-Dec-2019 06:50:21

921 Views

Let us first create a stored procedure −mysql> delimiter // mysql> create procedure declare_demo_sp()    begin    declare Value1 int;    declare Value2 int;    set Value1=100;    set Value2=2000;    select Value1,Value2,Value1*Value2 as MultiplicationResult;    end    // Query OK, 0 rows affected (0.00 sec) mysql> delimiter ;Call a stored procedure using CALL command −mysql> call declare_demo_sp();This will produce the following output −+--------+--------+----------------------+ | Value1 | Value2 | MultiplicationResult | +--------+--------+----------------------+ |    100 |   2000 |               200000 | +--------+--------+----------------------+ 1 row in set (0.00 sec) Query OK, 0 rows affected (0.00 sec)

Log Function in PHP

karthikeya Boyini
Updated on 27-Dec-2019 06:49:59

248 Views

The log() function Returns the natural logarithm of a number.Syntaxlog(num, base)Parametersnum − The value for which you want to calculate the logarithmbase − The logarithmic baseReturnThe log() function Returns the natural logarithm of a number.Example Live DemoOutput0ExampleLet us see another example − Live DemoOutput-INFExampleLet us see another example − Live DemoOutput2.3025850929940.99325177301028

Check If MySQL Entry Exists and Overwrite Other Columns

AmitDiwan
Updated on 27-Dec-2019 06:48:48

252 Views

For this, use INSERT ON DUPLICATE KEY UPDATE command. Let us first create a table −mysql> create table DemoTable1891    (    FirstName varchar(20),    UNIQUE KEY(FirstName)    ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1891 values('Chris') on duplicate key update  FirstName='Robert'; Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1891 values('David') on duplicate key update  FirstName='Robert'; Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1891 values('Chris') on duplicate key update  FirstName='Robert'; Query OK, 2 rows affected (0.00 sec)Display all records from the table ... Read More

Select Data and Set Value to Boolean Based on Timestamp Column in MySQL

AmitDiwan
Updated on 27-Dec-2019 06:47:30

404 Views

For this, use IF(). Let us first see the current date −mysql> select curdate(); +------------+ | curdate()  | +------------+ | 2019-12-10 | +------------+ 1 row in set (0.00 sec)Let us first create a table −mysql> create table DemoTable1890    (    DueDate timestamp    ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1890 values('2017-12-10'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1890 values('2021-12-10'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1890 values('2018-04-24'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1890 ... Read More

Advertisements