Home >Backend Development >PHP Tutorial >Basic syntax for getting started with php
I haven’t written an article for a while since I started my blog. Today I will introduce the basic syntax of PHP. In terms of syntax, PHP is relatively similar to C++. Okay, let’s not talk nonsense and let’s get straight to the code.
<?php //php代码必须包含在中间 //有时候?>可以省略,条件是php代码结尾后不再有其他内容 //php中变量无需声明类型 $num = 1; //if语句 if($num == 1){ $total = 1; }else{ $total = 0; } //循环结构 while($total < 10){ $total++; } //当然循环结构还包括for、do while //下面演示输出内容 echo $total; //echo用于打印内容,上面的程序输出$total的内容 //自定义函数 function addOne($value){ $value++; return $value; } //php中函数不用指定返回类型,return的数据类型可以任意,也可以不return
That’s all for today. Next time I will introduce how to use php for mysql database operations.
H The above introduces the basic grammar of PHP, including the content. I hope that friends who are interested in PHP tutorials are helpful. For more related content, please pay attention to PHP Chinese (www.php.cn)!