search
Homephp教程php手册PHP function learning - PHP function review_php basics

1.print_r()
Print easy-to-understand information about the variable. If it is an array, the structure information of the array is displayed.
For example:
Copy code a> The code is as follows:

$a = array ('a' => 'apple', ' b' => 'banana', 'c' => array ('x', 'y', 'z'));
print_r ($a);
?>

axgle comments: Viewing the structural information of any array is an essential tool for program debugging. For any "function" whose return result is an array, just print_r and all the details will be clear at a glance!
2.var_export()
Output or return a string representation of a variable
This function returns structural information about the variable passed to the function, it is similar to print_r() , the difference is that the representation returned is legal PHP code.
You can return a representation of a variable by setting the function's second argument to TRUE.
For example:
Copy code The code is as follows:

$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 php code~~ Then you can save it as a php file.
What to do when saving as a php file? Haha, this can be used as a "cache", and you can include it directly when needed.
3.file()
file() returns the file as an array. Each element in the array is a corresponding line in the file, including newlines. On failure file() returns FALSE.
Copy code The code is as follows:

// Copy a file Read into an array.
$lines = file('test.txt');
//View the structure of this array
print_r($lines);
?>

axgle comments: The file() function is a function that surprised me very much when I first came into contact with PHP. Compared with the extremely troublesome experience I had in reading and writing
files in C language and VB, at that time I felt that there was no more convenient way to read and write files than the file() function.
4.phpinfo()
Print php-related information, such as PHP version, function support, global variables, etc.
For example:
phpinfo();
?>
axgle comments: A simple function that allows you to 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)
Read the entire file into a string. The file_get_contents() function is used to read the contents of the file into a character The preferred method in strings. If the operating system supports it, memory mapping technology will also be used to enhance performance.
For example:
$data = file_get_contents('test.txt');
echo $data;
?>
6. file_put_contents (Note: PHP 5)
Write a string directly to the file.
For example:
//The address of an image
$url="http:/ /...test.com/plmm.jpg";
//Read binary "string"
$data=file_get_contents($url);
//Save to your own computer
file_put_contents("Beauty.jpg",$data);
?>
axgle comments: If you find that the pictures on a certain beauty picture website are named such as 1.jpg, 2.jpg...
ok, use a for loop to catch all the "beauties", don't get too excited and make your girlfriend
jealous~~~
7.function_exists
If the function exists, return true
For example:
//If the function does not exist, customize the function
if(!function_exists('file_put_contents')) { function file_put_contents($filename,$data) {
$fp=fopen($filename,"wb");
fwrite($fp,$data);
fclose($fp); }
}
?>
8.get_defined_functions
Returns an array to get all defined php functions.
For example:
Copy code The code is as follows:

$arr = get_defined_functions();
print_r($arr);
?>

axgle comments: Now you know all the function names. If you want to know the usage of a certain function, you can use the form http://www.php.net/function_name to check it online. "Cure all diseases, diagnose all kinds of difficult problems, and cure the disease~~~~" 9.get_declared_classes
Returns an array to get all defined php classes.
For example:
Copy code The code is as follows:

$arr = get_declared_classes();
print_r($arr);
?>

axgle comments: I believe you can see this function after running Example 8. When you run this function in php4, you can only get a few classes; but if you use php5, you will see dozens of predefined php classes in this example! It can be seen that php5 has been enhanced a lot in object-oriented aspects.
10.exit
Outputs a message and stops the current script. (Note: Like echo, this is not a "function", but a "statement").
For example:
echo "Statement 1";
exit("The following statement 2 will not be output");
echo "Statement 2";
?>
axgle comments: It is useful for debugging programs and finding error locations.
There are many more useful PHP functions, and there are some very interesting PHP functions to share. I will introduce them when I have time.
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
php函数返回值可以有几个php函数返回值可以有几个Apr 26, 2022 pm 08:14 PM

php函数返回值只能有一个。在PHP中,函数返回值使用return语句定义,语法“return 返回值;”。return语句只能返回一个参数,即函数只能有一个返回值;如果要返回多个值的话,就需在函数中定义一个数组,将返回值存储在数组中返回。

php传参都是字符串吗php传参都是字符串吗Dec 15, 2022 pm 03:07 PM

不是,php传参可以是字符串、数字、布尔值、数组等。从PHP5.6版本开始支持传递数组参数,函数的形式参数可使用“…”来表示函数可接受一个可变数量的参数,而可变参数将会被当作一个数组传递给函数,语法“function 函数名(...$arr){//执行代码}”。

php函数的参数赋值有哪几种php函数的参数赋值有哪几种Apr 24, 2022 pm 12:10 PM

php函数的参数赋值有3种:1、值传递赋值,将实参的值复制一份再赋值给函数的形参;2、引用传递赋值,把实参的内存地址复制一份,然后传递给函数的形参,进而将实参值赋值给形参;3、直接给函数的参数指定默认值,语法“函数名(参数变量='值')”。

详细介绍PHP函数和方法的区别详细介绍PHP函数和方法的区别Mar 24, 2023 am 09:45 AM

随着互联网技术的发展,PHP已经成为了非常流行的开发语言之一。身为一个PHP开发者,了解PHP函数和方法的区别是非常重要的,因为它们在编写代码的时候都是必不可少的。在本文中,我们将详细介绍PHP函数和方法的区别。

PHP函数的命名规范及规则PHP函数的命名规范及规则May 19, 2023 am 08:14 AM

PHP作为一种非常流行的脚本语言,有着强大的函数库支持,其函数的命名规范和规则对于开发效率和代码可读性都有着重要的影响。本文将介绍PHP函数的命名规范及规则。一、命名风格在PHP中,函数名需要严格符合命名规范和规则,规范主要包括两个方面:命名风格和命名规则。1.下划线命名法下划线命名法是PHP函数命名最常用的方式,也是官方推荐的一种方式。遵循这种方式的函数名

PHP函数的迭代器函数PHP函数的迭代器函数May 19, 2023 am 08:11 AM

随着现代编程语言的不断发展,编程的效率和功能性也不断提高,其中PHP作为一种广泛使用的服务器端脚本语言,也在不断地更新和完善其自身的功能列表。PHP函数的迭代器函数就是其中的一种新功能,为PHP程序员提供了更加灵活和高效的编程方式。在本文中,我们将详细介绍PHP函数的迭代器函数的相关知识。什么是PHP函数的迭代器函数?在介绍PHP函数的迭代器函数之前,我们首

php中递归函数是啥意思php中递归函数是啥意思May 31, 2022 pm 12:01 PM

在php中,递归函数指的是自调用函数,也就是函数在函数体内部直接或间接地自己调用自己;使用递归函数时,需要在函数体中附加一个判断条件,以判断是否需要继续执行递归调用,当条件满足时会终止函数的递归调用。

PHP函数的MSSQL函数PHP函数的MSSQL函数May 18, 2023 pm 11:31 PM

PHP是一种开源的服务器端脚本语言,通常用于开发Web应用程序。PHP具有易学易用、灵活、性能优异等优点,因此在Web开发领域得到了广泛应用。而MSSQL作为一种流行的关系型数据库管理系统,也被PHP所支持。在PHP中实现MSSQL数据库操作,需要使用MSSQL函数。MSSQL函数可用于连接数据库、执行查询语句、读写数据库中的数据等操作。接下来,将详细介绍一

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

Hot Tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function