Home > Backend Development > PHP Tutorial > Detailed explanation of php5 and mysql5 web development technology-3 variables, expressions and constants_PHP tutorial

Detailed explanation of php5 and mysql5 web development technology-3 variables, expressions and constants_PHP tutorial

WBOY
Release: 2016-07-14 10:08:59
Original
1131 people have browsed it

1. Definition, naming and classification

Divided into three types: scalar variables, array variables and objects
2. Printing and output variables
echo statement
printf() function
          Example: :
                                                                        printf("%d bootles of beer on %s", 100, "the wall");
printf("The %2$s likes to %1$s", "bark","dog");
sprintf() function
Example:
$formatted= fprintf("%01.2f",$var);
3. Display arrays and objects
print_r(array and variable);
var_dump (array variable object)
var_export (array variable object) The representation of the variable can be returned by setting parameters
          Example:
 $v = var_export($a,true); //Return the source code of php and use it directly in the array of php script
4. Data types supported by php variables
Integer, double, character, Boolean
Array, object, resource(Resource)
NULL
There are two ways to quote strings: double quotes and single quotes
Get and set variable type: gettype()/settype()
Arrays and objects are called conforming data types
5. Variables of variables
$var_name = 'php5';
$$var_name = ''php5 web development details;
echo $php5;
6. Super global variable array
$_GET[]
$_POST[]
$_COOKIE[]
$_SESSION[]
$_ENV[]
$_SERVER[]
$_FILES[]
$_REQUEST[]
$_GLOBALS[]
7. Variable operator
There is a lot of content, only the categories are listed without specific enumeration.
Arithmetic
Assignment
String concatenation
Pre and post addition and subtraction
Reference & After reference assignment, the variables have the same memory address
Ternary operator
Comparison operation
Boolean operator
Bit operator
Other operators:
1. Error suppression @
2. External command execution
                    $out = ·dir c:·
                      print_r($out);  
                    $our = shell_exec("dir");
echo $out;
The results of the two functions are the same, and the result is placed in a array; shell_exec () method puts the result in a scalar variable
8. Variable and script processing
isset()
unset()
empty()
is_array()is_integer()is_numeric()
9. Data conversion
Force type conversion of variables:
(array)
(bool)/(boolean)
(int)
(object)
(real)/(double)/(fload)
(string)
Others:
(1)intval($var):
(2)HereDoc
HereDoc allows embedding some large text content in php, such as email templates or some html or text content.
$string = 'hello';
$output = <<
The value of $string in HEREDOC is $string
MYDOC
echo $output;
The output result is: the value of $string in HEREDOC is hello
(3) escape character
n, t , \ ,$ ,''
(4) Numeric conversion function
chr($var) : Return the corresponding ASCII character according to the value of $var;
ord($string) returns the ASCII code value of the first character of the string;
10. Constant definition and magic constants
define("CONSTANT_NAME", constant value)
__LINE__
__FILE__
__FUNCTION__
__CLASS__
__METHOD__

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/477716.htmlTechArticle1. Definition, naming and classification are divided into three types: scalar variables, array variables and objects 2. Printing and output Variable echo statement printf() function example: printf(%d bootles of beer on...
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