should not test two floats for equality. This gives a value of 0 for even numbers and a value of 1 for odd numbers. In this script, we create a method swap which takes two numbers as an argument and print the value of both numbers after swapping. PHP Program to print Random Numbers; JavaScript to print Prime Numbers between two numbers! Please note that the ternary operator is an expression, and that it Another conditional operator is the "? The PHP manual recommends using the random_bytes() function for cryptographically secure integers. In the above example For loop is used because we know how many times loop iterate. Don't use the simple equality operators (==, !=), because ($a == $b) will return TRUE in many situations where ($a eq $b) would return FALSE. Subtracting Two Numbers. The BETWEEN operator is inclusive: begin and end values are included. Contribute your code and comments through Disqus. Add two Numbers Program in PHP Swap two numbers Program in PHP. be careful when trying to concatenate the result of a ternary operator to a string. return-by-reference function will therefore not work and a warning is The values can be numbers, text, or dates. Example: . Take note when grouping ternary operations that return either boolean or integer concatenated to a string: a function to help settings default values, it returns its own first non-empty argument : Note: The ternary shortcut currently seems to be of no use in dealing with unexisting keys in an array, as PHP will throw an error. This can be useful if you are presenting statistics, etc. Just copy the code in to your page and use it for creating or generating random number between two different numbers. numeric string, PHP: Calculate the percent difference between two numbers. The former name merely notes that it has three arguments without saying anything about what it does. evaluates to true, and expr3 otherwise. Note: The mt_rand() function is said to be four times faster and it produces a better random value.