Grammar based PHP ternary operator and other operators

 

Ternary operator and other operators

There are also some special operators and symbols, let us explain. We may need to use later. Linear motor selection

symbol Explanation
? $ X really snippet: false code segment Determine whether the case is true or false true: false cases;?
`` (Backtick) Backticks interposition of substituting commands, execute system commands, functions equivalent to shell_exec
@ Single-line error suppression, this line is wrong not to let it show out, inefficient use is not recommended
=> Array subscript accessors
-> Object Access Fu
instanceof Determine if an object from a class, if the return is true, and false if not

Ternary operator, if ... else equivalent structures. However, the ternary operator wording more concise, the following syntax:

? $ X really snippet (can only write a code): pseudo-code segment (can only write a code);

code show as below:

<?php
$x = true;

$x ? $y = 5 : $y = 6;
//输出5
echo  $y;

?>

Backticks even more special, we often need to display the IP address, we can not display windows of the IP address in PHP inside it? With anti-quotation marks, we can execute commands (though some virtual servers are prohibited execute these commands script):

<?php
echo '<pre>';

echo `ipconfig`;
echo '</pre>';
?>

You execute the code above to see the effect, it is not displayed and a bunch of IP addresses and IP related parameters of your machine?

@ Symbol refers to a single line to suppress errors in subsequent chapters we will explain to. To understand the level here.

<? PHP 
// adfsafasdfasfasdfdsadf.txt open a file that does not exist, you will find that running about the error. 
@ @ Again in front of a symbol plus see the effect of 
$ FP = the fopen ( 'adfsafasdfasfasdfdsadf.txt', 'R & lt'); 

// @ $ FP = the fopen ( 'adfsafasdfasfasdfdsadf.txt', 'R & lt'); 

?>

Array subscript operator access, will also have a chapter to explain, here to learn what you can:

<? PHP 

$ = Data Array ( 'siNA' => 'Sina', 'sohu' => 'Sohu'); 

?>

Object Access Fu -> instanceof and understand all levels, and they will have a special section to explain:

? <PHP 
// instantiate an object 
$ obj = new new StdClass (); 

// a determination is made an object instance of a class, is performed if it is true 
IF (the instanceof the stdClass $ obj) { 
   echo 'true'; 
the else {} 
   echo 'false'; 
} 
// append to the object obj property is a member of the username 
$ obj -> username = 'PHP Chinese network'; 

echo $ obj -> username; 

>?

All the above example, in addition to the ternary operator, @, Backspace. Other levels are learning to understand, explain at a later time. You know this symbol can be.

Guess you like

Origin www.cnblogs.com/furuihua/p/12061213.html