PHP basic syntax and data type learn notes

Source: Internet
Author: User

PHP basic syntax and data type:

(1), PHP basic syntax:

1, htm and PHP mixed
2, a statement to; (semicolon ends)
3, how to define a variable, and the use of variables

(2), PHP data operation type

Four scalar types:
Boolean (Booleans) understood as true or false
Integer (integral type)
Float (floating-point type, also "double") is interpreted as a decimal type
String (strings)

Two types of composite:
Array (arrays)
Object (Objects)

(3) PHP Five types of operations

1. Arithmetic operation

2, assignment operations (such as: $a =100)

3, Comparison operations (such as: $a < $b)

4, logical operation (such as: $a && $b)

5, incremental condensation operation (such as: $a + +)

(4) Switch conditional statement

Switch Conditional statement

<?php

$i = 1;

Switch ($i) {
Case 0;
The value of echo "I" is 0″;
Break
Case 1;
The value of echo "I" is 1″;
Break
Case 2;
The value of echo "I" is 2″;
Break
Default:echo "The above several values are not";

}

?>

Break n Jump Loop statement

Break n jump out of n-tier loops

Cases:

<?php
For ($i =1 $i <=5; $i + +) {
echo "i=". $i. " <br> ";
For ($j =1 $j <=5; $j + +) {
echo "&nbsp;&nbsp;j=". $j. " <br> ";
For ($k =1 $k <=5; $k + +) {
echo "&nbsp;&nbsp;&nbsp;&nbsp;k=". $k. " <br> ";
if ($k ==2) {
Break
}
}
if ($j ==3) {
Break 2;
}

}
echo "<br>";
}
?>

(5) Do While loop

<?php

Do a second judgment first.
do{
echo "Execution loop";
$a + +;
}while ($a >100);/note here's a semicolon.
echo "<br>";

To judge and execute first.
while ($a >100) {
echo "Execution loop";
$a + +;
}
?>

Functions that are commonly used in PHP arrays

foreach ($arr as $key => $val) {}//traversal array

Count ($arr)//counts the length of an array

Is_array ($arr)//array of Judgments

Explode ("key", $STR)//split string array

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.