Li Yanhui PHP video tutorial season 1 resource sharing

黄舟
Release: 2023-03-15 16:12:01
Original
3246 people have browsed it

php is one of the most popular languages ​​currently. As a master figure in the PHP training industry, Li Yanhui's course explanations are clear and comprehensive. His PHP tutorial video is a classic and widely circulated on the Internet. This course is his first season video, about the basic knowledge of php.

Li Yanhui PHP video tutorial season 1 resource sharing

Course playback address: http://www.php.cn/course/392.html

The teacher’s teaching style:

The teacher’s lectures are vivid, witty, witty, and touching. A vivid metaphor is like the finishing touch, opening the door to wisdom for students; an appropriate humor brings a knowing smile to students, like drinking a glass of mellow wine, giving people aftertaste and nostalgia; a philosopher's aphorisms, cultural references Proverbs are interspersed from time to time in the narration, giving people thinking and warning.

The more difficult part in this video is the PHP custom function:

Generally speaking, redundant code is bad. Rewriting the code again and again is not only a waste of time, but also looks shoddy from a layout and structure perspective. Like all good programming languages, PHP uses many methods to alleviate the problem of redundant code. The most common and easiest to implement method is to use functions.

one. Standard functions

There are more than 1,000 standard functions in the standard PHP distribution package. These standard functions are built into the system and can be used directly without the need for users to create them themselves.

<?
echo md5(&#39;123456&#39;);   //MD5函数对字符串进行加密处理
?>
Copy after login

2. Custom functions

PHP built-in functions allow interacting with files, using databases, creating graphics, and connecting to other servers. However, in actual work, there are many times when things are needed that the creators of the language could not foresee.

Declaring a function allows us to use our own code like built-in functions. Simply call this function and provide it with the necessary parameters. This means that the same function can be called and reused multiple times throughout the script.

Create function

<?
function functionName() {
echo &#39;这是一个无参无返回自定义函数&#39;;
}
?>
Copy after login

Call function

<?
functionName();
?>
Copy after login

Function naming

1. The function name cannot be the same as the existing function name name.

2. The function name can only contain letters, numbers and underscores.

3. The function name cannot start with a number.

Function call containing parameters and no return

<?
function functionArea($radius) {
area=radius * $radius * pi();
echo $area;
}
 
functionArea(10);
?>
Copy after login

Function call containing parameters and returning: Use the return() statement to report to the function caller Returns an arbitrary deterministic value, returning program control to the caller's scope.

<?
function functionArea($radius) {
return radius∗radius * pi();
}
 
echo functionArea(10);
?>
Copy after login

Function call containing default parameters: You can specify a default value for the input parameter. If no other value is provided, the default value will be automatically assigned to the parameter.

<?
function functionArea($radius=10) {
return radius∗radius * pi();
}
 
echo functionArea();
?>
Copy after login

Function call that returns multiple values: It can be constructed by returning an array and then using the list() function.

<?
function functionInfo(name,age,$job) {
userInfo=array(name,age,job);  //可以用追加的方式比较常用
return $userInfo;
}
 
list(name,age,$job) = functionInfo(&#39;吴祁&#39;,19,&#39;学生&#39;);
echo 今年name.′今年′.age.&#39;岁了,目前还是个&#39;.$job;
?>
Copy after login

Function calls containing parameters passed by reference: Passed by reference, modifications to parameters within the function can also be reflected outside the scope of the function.

<?
$prices = 50;
$tax = 0.5;
function functionPrices(&prices,tax) {
prices=prices + (prices∗tax);
tax=tax * 2;
}
 
functionPrices(prices,tax);
echo $prices;
echo &#39;<br />&#39;;
echo $tax;
?>
Copy after login

Please note that function calls will not be case-sensitive, so calling functionname(), FunctionName(), or FUNCTIOINNAME() are all valid and will all return the same results. For convenience, all are in lowercase here.

It is important to note that function names and variable names are different. Variable names are case-sensitive, so $Name and $name are two different variables, but Name() and name() are the same function.

The above is the detailed content of Li Yanhui PHP video tutorial season 1 resource sharing. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template