Home > Backend Development > PHP Tutorial > PHP basic syntax examples

PHP basic syntax examples

WBOY
Release: 2016-07-29 09:15:53
Original
1303 people have browsed it

demo1:

//Use two ways to output hello world and line break
echo "hello word".'
';
print "hello word2".'
';
//Define variable assignment, and add it again and output
$a=1234;
echo $a.'
';
echo + +$a.'
';

?>

demo2:

//Customize variable case and underline
//Define Boolean variables and output
$bo=true;
echo $bo.'
';
//Define integer variable and output
$bo=12;
echo $bo. '
';
//Define floating point variables and output
$bo=1.001;
echo $bo.'
';
// Define string variables and output them. Double quotes support escape characters, and single quotes support simple single quote escape.
$bo="oren word";
echo $bo.'
';
//Two ways to define arrays
$bo=array(1,2, 3,4);
//$bo=arrar("A"=>1,"B"=>2);
echo $bo[1];

?>

demo3:

//Introduction and application of PHP operation types.
//1. Arithmetic operation
echo 4+5*5/9;
//2. Assignment operation
$a=1;
echo $a.'
';
$a+=2;
echo $a.'
';
$a*=3;
echo $a.'
//3. Comparison operation, get Boolean value, true will output 1, false will output nothing.
//echo 1==2;
//echo 3!=2;
//echo 5<3;
//echo "ok"=="ok";
//The double equals sign only judges the numerical value; the triple equals sign will judge the type first, both the numerical value and the type.
echo (1=='1').'
';
//echo 1===='1';
//4. Logical operations.
echo (1&&1).'
';
echo (0&&1).'
';
echo (1||1).'
';
echo (0||1).'
';
//5. Increment and decrement operation
$b=1;
echo $b++." ";
echo ++$b."
?>
Copyright Statement: This article is an original article by the blogger and may not be reproduced without the blogger's permission. The above introduces the basic syntax examples of PHP, including aspects of content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template