PHP Learning officially set sail (2)

Source: Internet
Author: User
Data type
PHP supports integers, floating-point numbers, strings, arrays, and objects. The variable type is usually not determined by the programmer and is determined by the PHP run process to convert a variable of some type to the specified type using CAST or function Settype ()


A numeric value type can be an integer or a floating-point number. You can use the following statement to assign a value to a number:
$a = 1234; # decimal number to understand
$a =-123; # Negative numbers to understand
$a = 0123; # octal number (equal to 83 of decimal number)
$a = 0x12; # hexadecimal number (equal to 18 of decimal number)
$a = 1.234; # floating-point "double-precision number" to understand
$a = 1.2e3; # The exponential form of double-precision numbers

Here you know integers and decimals ....

String
A string can be defined by a field that is enclosed by single or double quotation marks. Note that the strings quoted in the enclosed quotation marks are literally defined, and the strings drawn from the double quotation marks can be expanded. Also, you can use backslashes \ To include escape sequences and convert characters in a string in a double-quote string. Examples are as follows:

$first = ' Hello '; $second = "World"; $full 1 = "$first $second"; # Generate Hello World $full 2 = ' $first $second '; # generates $first $second

It is used to concatenate two strings together. Instead of +, this should be noted
$string = $first. $second; The result is HelloWorld.

The operator PHP has the commonly seen operators in c,c++ and Java. The precedence of these operators is also consistent. The assignment also uses "=". Arithmetic and characters the only one of the following operators is about characters:
$a + $b: Plus
$a-$b: minus
$a * $b: Multiply
$a/$b: except
$a% $b: modulo (remainder)
$a. $b: String connection logic and comparison logical operators are:
$a | | $b: Or
$a or $b: or
$a && $b: With
$a and $b: With
$a XOR $b: XOR (True if $ A or $b is true, False if both)
! $a: Non-
Comparison operators are:
$a = = $b: equal
$a! = $b: Unequal
$a < $b: less than
$a <= $b: less than or equal to
$a > $b: Greater Than
$a >= $b: greater than or equal to
As with C, PHP has a triple operator (?:). Bitwise operators also exist in PHP.

It's very simple.

Control process Structure
PHP has the same process control as C.
if (expression two)
. . .
}
ElseIf (Expression II)
{
. . .
}
Else
{
. . .
}

Switch is the best replacement for multiple If-elseif-else structures:

Switch ($i) {case 0:print "I equals 0", Case 1:print "I equals 1", Case 2:print "I equals 2";}

Loop structure
while (expression)
{
. . .
}



Do
{
. . .
}
while (expression);



for (expression one; expression two; expression three)
{
. . .
}

There's a loop for foreach.


Break, continue
Break interrupts the current loop control structure.
The continue is used to jump out of the remaining current loop and continue with the next loop.


These are very simple, and C language are the same, it is all over ...

  • 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.