PHP 2: Operator and Process Control

Source: Internet
Author: User

1 operator

The combination priority of operators is not described here. brackets are generally used to solve this problem.

1.1 Arithmetic Operators

It is common, such as +-*/%-. Note that the % operation is consistent with the symbol of the numerator.

1.2 value assignment operator

For example, = + =-=

1.3-bit operator

For example, & | ^ ~ <>

1.4 comparison Operators

$ A ==$ B: After the type conversion, the values are equal.

$ A ===$ B has the same type and the value is equal.

! = <>

! =

<=

>>=

Error Control 1.5

@ Expresion ignore error messages generated by expressions

1.6 execution Operator

''Is used to execute shell commands, which is equivalent to shell_exec ()

1.7 increase or decrease Operator

++

--

Supports auto increment and decrement operations before and after

1.8 logical operators

And == &&

OR = |

XOR

Not =!

1.9 string Operators

. String connection

. = String connection and value assignment

1.10 array Operators

+ Set and Operation

= Same set comparison operation

=== Comparison operations with the same set and the same position

! = Set unequal comparison operation

! = Not met === comparison operation

1.11 type operators

$ A instanceof class

2. Process Control

2.1 If... else/else if

<?phpif ($a > $b) {    echo "a is bigger than b";} elseif ($a == $b) {    echo "a is equal to b";} else {    echo "a is smaller than b";}?>

2.2 While/do... while

<?php/* example 1 */$i = 1;while ($i <= 10) {    echo $i++;  /* the printed value would be                   $i before the increment                   (post-increment) */}/* example 2 */$i = 0;do {    echo $i;} while ($i > 0);?>

2.3 For/foreach

<?php/*for  example 1 */for ($i = 1; $i <= 10; $i++) {    echo $i;}/* foreach example 1: value only */$a = array(1, 2, 3, 17);foreach ($a as $v) {    echo "Current value of \$a: $v.\n";}/* foreach example 2: value (with its manual access notation printed for illustration) */$a = array(1, 2, 3, 17);$i = 0; /* for illustrative purposes only */foreach ($a as $v) {    echo "\$a[$i] => $v.\n";    $i++;}/* foreach example 3: key and value */$a = array(    "one" => 1,    "two" => 2,    "three" => 3,    "seventeen" => 17);foreach ($a as $k => $v) {    echo "\$a[$k] => $v.\n";}/* foreach example 4: multi-dimensional arrays */$a = array();$a[0][0] = "a";$a[0][1] = "b";$a[1][0] = "y";$a[1][1] = "z";foreach ($a as $v1) {    foreach ($v1 as $v2) {        echo "$v2\n";    }}/* foreach example 5: dynamic arrays */foreach (array(1, 2, 3, 4, 5) as $v) {    echo "$v\n";}

2.4 Switch

<?phpswitch ($i) {    case 0:        echo "i equals 0";        break;    case 1:        echo "i equals 1";        break;    case 2:        echo "i equals 2";        break;}?>

2.5 break/continue

Omitted

2.6 declare

Indicates the command. Currently, the code of a specified file is used, as shown in figuredeclare(encoding='ISO-8859-1');

2.7 return

Return from the function

2.8 require/include

Used to include the specified file. The two functions are almost the same. The difference is that the processing failure method is different. The former will return fatal, the latter is only warning, and the script will continue to be executed.

require 'prepend.php';

include 'vars.php';

Require_once and include_once work in the same way. The difference is that if the specified file already exists, it is no longer included.

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.