PHP Basics. 1. output data to the browser: print (), echo (), printf (), sprintf (), print (), and echo () the statement outputs the data passed in to the browser pintf () to output static text and one or more 1 data to the browser: print (), echo (), printf (), sprintf (),
- Print () and echo () statements both output the data passed in to the browser.
- Pintf () outputs a hybrid statement consisting of static text and dynamic information stored in one or more variables
- Compared with print (), sprintf () has the same function, but it assigns the output to a string instead of directly rendering it to the browser.
2. type-related functions:
- Gettype ()
string gettype(mixed var)
- Conversion type settype () boolean settype (mixed var, string type)
3. Variable Declaration: The variable always starts with the dollar sign $, followed by the variable name.
4 heredoc syntax provides a convenient way to output a large number of texts. Two identical identifiers are used, and two identical identifiers are text
Php
$ Website https
EchoEXCERPT // identifier
... // Text
Excerpt; // identifier
5 foreach statement: traversal elements (such as arrays) have two forms
- Foreach(Array_expr$ Value ){
Statement
}
-
Foreach(Array_expr$ Key $ value ){
Statement
}
Examples of the two syntax formats are:
Php
$ Links array(, Www.apache.org );
EchoOnline Resources:
";
Foreach($ Links$ Link ){
Echo";
}
Php
$ Links array(,
,
Echo "bOnline Resourcesbbr foreach ($ links as $ title => $ link ){
Echo "a href \" http $ title
";
}
6. file-containing statements: make the code reusable and intrusive, improve efficiency, refuse to work overtime, and cherish the programmer's life.
The difference between include (), include_once (), require () *** require () and include () is that regardless of the location of require (), the specified file must be included in require ().
7. return multiple values from the function: assume that you want to create a function (name, email address, address, and phone number) to obtain user data from the database ), then all the user's personal information is returned to the caller. Implement multi-value returned. the list () constructed by language can satisfy your wishes.
Php
FunctionRetrieveUserProfile (){
$ User [];
$ User [] jason@example.com;
$ User [];
Return$ User;
}
List($ Name, $ email, $ language) retrieveUserProfile ();
Echo;
8 arrays
Create an array: PHP is different from other computer languages in creating an array. you do not need to specify its size or use numbers.
Related functions include:
- Explode (separator, string, limit) // splits the string into an array. The first two parameters are required.
- Range (fist, secend, step) // Create and return an array containing the elements of the specified range. The first two parameters must exist.
- Is_array (mixed variable) // determines whether the variable type is an array type.
The http://www.bkjia.com/PHPjc/440263.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/440263.htmlTechArticle1 outputs data to the browser: print (), echo (), printf (), sprintf (), print (), and echo () the statement outputs the data passed in to the browser pintf () to output static text and one or more...