Common Troubleshooting Questions
1. Rand (Min,max) differs from Mt_rand (Min,max) if no optional parameter min and Max,mt_rand () are provided to return a pseudo-random number between 0 and Rand_max. For example, want a random number between 5 and 15 (including 5 and 15), with Mt_rand (5, 15).
Many of the old libc random number generators have some uncertainties and unknown characteristics and are slow. The rand () function of PHP uses the libc random number generator by default. The Mt_rand () function is informally used to replace it. The function uses the known characteristics of the Mersenne Twister as a random number generator, which can produce random values four times times faster than Rand () provided by LIBC.
2, PHP Echo, print, Print_r, printf, sprintf and Var_dump functions of the difference and use
1) Echo
Echo () is not actually a function, it is a PHP statement, so you do not need to use parentheses on it. However, if you want to pass more than one argument to Echo (), a parse error occurs when you use parentheses. and echo returns void and does not return a value, so it cannot be used to assign a value.
Example:
<?php $a = Echo ("55nav"); Error! Cannot be used to assign echo "55nav"; 55nav Echo ("55nav"); 55nav Echo ("55nav", "com"); An error occurred, with parentheses cannot pass multiple parameters echo "55nav", "com", "is", "web"; You can separate multiple values with commas without parentheses, and output 55nav com is web echo "55nav is good web."; The final display is a line of 55nav is good web.echo "$fistname com", regardless of whether the line is wrapped; If $firstname = "55nav", 55nav com.echo ' $firstname com will be output; Because the single quotation marks are used, the $firstname value is not output, but the output $firstname com12?>
2) Print
Print () is the same as Echo (), but the echo speed is a little bit faster than print. It is not actually a function, so you do not need to use parentheses on it. However, if you want to pass more than one parameter to print (), a parse error occurs when you use parentheses. Note that print always returns 1, which is different from Echo, which means you can use print to assign a value, but it doesn't make sense.
Example:
<?php $a = print ("55nav"); This is the allowed echo $a;//$a value is?>;
3) Print_r Function--print the values of predefined variables
The Print_r function prints easy-to-understand information about variables.
Syntax: Mixed print_r (mixed $expression [, BOOL return])
If the variable is a string, the integer or float will output its value directly, and if the variable is an array, it will output a formatted array for readability, which is the format of the key and value. Similar for object objects. Print_r has two parameters, the first is a variable, the second can be set to true, and if set to True, returns a string, otherwise returns a Boolean value of true.
Example:
<?php $a = "55nav"; $c = Print_r ($a); echo $c; The value of $c is true $c = Print_r ($a, ture); Echo $c; The value of the $c is the string 55nav?>
4) printf function
The printf function returns a formatted string.
Syntax: printf (format,arg1,arg2,arg++)
The parameters format is the converted format, starting with the percent sign ("%") to the end of the converted character. The following is the possible format value:
*%%– return percent symbol
*%b– binary number
*%c– characters in accordance with ASCII values
*%d– Signed decimal number
*%e– counting method (e.g. 1.5e+3)
*%u– unsigned decimal number
*%f– floating point (Local settings Aware)
*%f– floating point number (not local settings aware)
*%o– octal number
*%s– String
*%x– hexadecimal number (lowercase letter)
*%x– hexadecimal number (capital letter)
Arg1, arg2, arg++, etc. parameters will be inserted into the main string percent percent (%) Symbol. The function is executed incrementally, in the first% symbol, insert arg1, insert arg2 at the second% symbol, and so on. If the% symbol is more than the arg parameter, you must use a placeholder. After the placeholder is inserted in the% symbol, it consists of a number and a "\$". You can use numbers to specify the parameters that are displayed, see examples for details.
Example:
<?php printf ("My name is%s%s. "," "," "com"); My name is in the COM printf ("My name is%2\ $s%1\ $s", "1\$", "com"), or/////before S-Add the 2\$ ... Represents the location of the following parameter display, this line shows my name is COM 55?>
5) sprintf function
This function uses the same method as printf, except that the function writes the formatted string to a variable instead of the output.
Example:
<?php sprintf ("My name is%1\ $s%1\ $s", "on", "com"); You'll find nothing out of the $out = sprintf ("My name is%1\ $s%2\ $s", "on", "com"); echo $out; Output My name is com?>
6) Var_dump function
Function: The content, type, and length of the output variable's contents, type, or string. Commonly used to debug.
Example:
<?php $a =100; Var_dump ($a); Int (n) $a =100.356; Var_dump ($a); Float (100.356)?>