PHP Learning 1-Basic Knowledge variable definition, output display, (Eval, exit, die)

Source: Internet
Author: User

Basic knowledge

<? PHP
Echo "1, display_errors = on is displayed in PHP. ini. <br> ";
Echo "2, used to print echo and print <br> ";
Echo "the reason why Wamp cannot be used after installation is that IIS has been installed is that Apache cannot start the listener and stop IIS ";
Phpinfo (); // use a semicolon (;) to end each line of statements

/*
Display_errors = on is displayed in PHP. ini.

*/

/*
Multi-line comment
*/

// Single line comment
# Single line comment
?>

Knowledge about simple variables and simple Arrays
1. Hybrid encoding of HTM and PHP
2. A statement ends with a semicolon)
3. How to define a variable and how to use the variable

PHP Data Operation Type
Four scalar Variables
Boolean
Integer
Float, double
String
Two composite types
Array
Object

<? PHP
Echo "<br> ";
Echo "how to define a variable and use the variable <br> ";

$ A = 9;
Echo "$ ";
Echo "<br> ";
$ B1 = true; $ b2 = false;
$ F = 1.26;
$ S = "string type ";
Echo "int". $ A. "Boolean". $ B1. "float". $ F. "string". $ S;

$ Arr = array (1, 2, 3, 4, 5 );
$ Arr2 = array ("ID" => 100, "title" => "this is new ");
$ Arr3 = array (Array (1, 2, 3, 4), array (5, 6 ));
Echo "<br> ";
Echo $ arr;
Print_r ($ arr2 );
Echo "<br> ";
Echo $ arr3 [0] [3]. $ arr3 [1] [1];
Echo $ arr2 ['id'];

?>

Echo print [printf sprinitf] and array output print_r, var_dump, var_export

Bool printf (string format, argS) Format String, mainly used for string replacement

String sprintf (string format, argS) is basically the same as printf, but it can save the converted results to a string variable instead of output.

 

If the format is % 1, % 2, replace it with the corresponding variable in order

% D decimal

% B binary

% C integer converted into ASCII characters

% S integer to string

% F times accuracy converted to floating point

% O integer to octal

% X/x integer to lowercase or upper-case hexadecimal number

If yes, the number is left aligned.

 

Use echo and print

 

The echo function can use commas and dots to display strings without returning values. The print function can only use dots to connect to display strings.

 

Void echo ()

 

Int print (string $ tag)

 

Use the output Array
Print_r ($ array/$ var ),
Var_dump ($ OBJ/$ array/$ var ),
Var_export ($ OBJ/$ array/$ var)

Differences

Echo print printf can print variables, but it cannot display arrays and system super variable arrays.

Print_r and var_dump can not only print arrays, flags, but also Print Object content.

Var_dump not only prints arrays and scalar values, but also prints object content, but also prints boolean values and resources)

The var_export function returns structure information about the variables passed to it, similar to var_dump. The difference is that the returned content is legal in PHP.Code

 

 

 

 Eval () dynamically executes PHP statements, such

 

 
$ Str= '$ Var = 5 ;';Eval($ Str);Echo $ VaR;//Output 5

Exit () only accepts one parameter (can beProgramReturn value or string), or do not enter a parameter (no return value at this time). When 0 is passed to it, the program is terminated.

For example, if eixt (0) is used, the following statement will not be executed. If a string is given, the program will output as is when an error occurs, for example

 

$ Fp=Fopen() OrDie("File cannot be opened ")

 

Die () is a function with the same name as exit.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.