Ec (2); PHP function usage instructions, application examples, simplified comments, hope to help you learn php. 1. print_r () Prints easy-to-understand information about variables. If it is an array, the structure information of the array is displayed. For example: & lt; pre & gt; & lt ;? Php & nbsp; $ aarray (a & gt; apple, B & gt; banana, c & gt; array (x, y script ec (2 ); script
PHP function instructions, application examples, simplified comments, hope to help you learn php.
1. print_r ()
Prints easy-to-understand information about variables. If it is an array, the structure of the array is displayed.
For example:
$a = array ('a' => 'apple', 'b' => 'banana', 'c' => array ('x', 'y', 'z'));
print_r ($a);
?>
Axgle comment: Viewing the structure information of any array is a necessary tool for program debugging. If any returned result is an array "function", you only need print_r to check the details at a glance!
2. var_export ()
Outputs or returns a string representation of a variable.
This function returns the structure information about the variables passed to this function. It is similar to print_r (). The difference is that the returned representation is legal PHP code.
You can set the second parameter of the function to TRUE to return the expression of the variable.
For example:
$a = array (1, 2, array ("a", "b", "c"));
var_export ($a);
echo "";
$v = var_export($a, TRUE);
echo $v;
?>
Axgle Comment: In the above example, $ v = var_export ($ a, TRUE) returns the php code ~~ You can save it as a PHP file.
What is saved as a PHP file? This can be used as a "cache". You can include it directly when necessary.
3. file ()
File () returns the object as an array. Each element in the array is a corresponding line in the file, including line breaks. If file () fails, FALSE is returned.
// Read a file into an array.
$ Lines = file('test.txt ');
// View the structure of this array
Print_r ($ lines );
?>
Axgle comment: the file () function is a function that surprised me when I first came into contact with php. In C and vb
I felt that there was no more convenient file read/write method than the file () function.
4. phpinfo ()
Print php-related information, such as the PHP version, Function Support, and global variables.
For example:
Phpinfo ();
?>
Axgle Comment: A simple function that keeps you updated on the rapid development of php-if you pay close attention to the development of php ~~~~
5. file_get_contents () (Note: PHP 4> = 4.3.0, PHP 5)
The function of reading the entire file into a string. file_get_contents () is the preferred method for reading the file content into a string. If the operating system supports it, the memory ing technology will be used to enhance the performance.