Home >Backend Development >PHP Tutorial >PHP basic syntax and data types study notes_PHP tutorial

PHP basic syntax and data types study notes_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:50:35786browse

An entry-level article on basic PHP syntax and data types. I hope it can provide some help to all PHP beginners.

PHP basic syntax and data types:

(1), PHP basic syntax:

1. Mixed HTML and PHP
                                                                                                                                                                                                                      ​​​​​​​ 3. How to define a variable and how to use it

(2), PHP data operation type

Four scalar types:

                   boolean (Boolean type) understood as true or false type
                        integer (integer type)
Float (floating point type, also called "double") is understood as decimal type
String (string)

Two compound types:

                         array (array)
object

(3) Five operation types of PHP

1. Arithmetic operations

2. Assignment operation (such as: $a=100)

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

4. Logical operations (such as: $a&&$b)

5. Increment and decrement operations (such as: $a++)

(4) switch conditional statement

switch conditional statement

$i=1;

switch($i){

case 0;
echo "The value of i is 0";
          break;
case 1;
echo “The value of i is 1″;
          break;
case 2;
              echo “The value of i is 2″;
          break;
Default: echo "None of the above values";

}

?>

break n jump out of loop statement

break n jump out of n level loop

Example:

for($i=1;$i<=5;$i++){
echo “i=".$i."
";
for($j=1;$j<=5;$j++){
echo “ j=”.$j.”
”;
for($k=1;$k<=5;$k++){
echo “ k=”.$k.”
”;
If($k==2){
         break;
}
            }
if($j==3){
Break 2;
}
}

echo “
”;
}
?>

(5) do while loop

//Execute once before judging

do{
echo “Execution loop”;
$a++;
}while($a>100);//Note there is a semicolon
echo “
”;
//Judge first and then execute

while($a>100){
echo “Execution loop”;
$a++;
}
?>

Functions commonly used in PHP arrays

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

count($arr)//length of statistical array

is_array($arr)//Judge array

explode(“key”,$str)//Split the string into an array

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632633.htmlTechArticleAn entry-level article on basic PHP syntax and data types. I hope it can provide some help to all PHP beginners. . PHP basic syntax and data types: (1), PHP basic syntax: 1....
Statement:
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