Function
PHP function instructions, application examples, concise comments, I hope to learn from your PHP help.
1.print_r ()
Print easy-to-understand information about variables and, if they are arrays, display the structure information for the array.
For example:
<pre>
<?php
$a = Array (' A ' => ' Apple ', ' B ' => ' banana ', ' C ' => array (' x ', ' y ', ' z '));
Print_r ($a);
?>
</pre>
Axgle Reviews: Viewing any array structure information is an essential tool for program debugging. For any return result is an array of "functions", as long as Print_r, all 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 variable passed to the function, which is similar to Print_r (), and differs in that it returns a representation that is valid for PHP code.
You can return the representation of a variable by setting the second argument of the function to TRUE.
For example:
<pre>
<?php
$a = Array (1, 2, Array ("A", "B", "C"));
Var_export ($a);
echo "
$v = Var_export ($a, TRUE);
Echo $v;
?>
</pre>
Axgle Reviews: In the example above, $v = Var_export ($a, TRUE) returns the PHP code OH ~ ~ so you can save it as a PHP file.
What do I save as a php file? Oh, this can be used as a "cache", when needed, you can include it directly.
3.file ()
File () returns the files as an array. Each element in the array is the corresponding line in the file, including line breaks. If failure file () returns FALSE.
<pre>
<?php
Reads a file into the array.
$lines = File (' Test.txt ');
View the structure of this array
Print_r ($lines);
?>
</pre>
Axgle Reviews: The file () function is a function that I was surprised at the beginning of my exposure to PHP. Compared to the previous I in C language and VB
The incredibly cumbersome experience of file reading and writing made me feel like there was no more convenient way to read and write files than the files () function.
4.phpinfo ()
Print information about PHP, such as PHP version, feature support, global variables, and so on.
For example:
<?php
Phpinfo ();
?>
Axgle Comments: A simple function, let you always understand 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)
Reads the entire file into a string. The File_get_contents () function is the preferred method for reading the contents of a file into a string. Memory-mapping technology is also used to enhance performance if supported by the operating system.
For example:
<?php
$data = file_get_contents (' test.txt ');
Echo $data;
?>
6. File_put_contents (Note: PHP 5)
Writes a string directly to the file.
[1] [2] Next page