codecamp

PHP语句

PHP教程 - PHP语句

PHP代码块

代码块是被分组为一个单元的语句的列表。

句法

在PHP中,我们使用{}来包装代码块并通知编译器说“这是一组言论"。

例子

下面的代码组将两个打印语句结合在一起并输出A和B,如果天空的颜色是蓝色的。

<?PHP

$sky_color = "blue";

if($sky_color == "blue") {
     print("A \n");
     print("B \n");
}

print("Here I am from www.w3cschool.cn.");

?>

上面的代码生成以下结果。



实施例2

下面的代码显示了如何创建三个简单语句。

<?php
  //an expression statement
  2 + 3;

  //another expression statement
  print("PHP!");

  //a control statement
  if(3 > 2)
  {
    //an assignment statement
    $a = 3;
  }
?>


上面的代码生成以下结果。



PHP评论

在编程中,注释是我们的代码的描述。

标记注释的语法

在PHP中有三种方法来创建注释:

  • //
  • /* */, and
  • #.

笔记2

// 表示“忽略此行的其余部分,

     <?php
             print "This is printed\n";
             // print "This is not printed\n";
             # print "This is not printed\n";
             print "This is printed\n";
      ?>
      

上面的代码生成以下结果。

/* means "Ignore everything until you see */."
     <?php
             print "This is printed\n";
             /* print "This is not printed\n";
             print "This is not printed\n"; */
      ?>

上面的代码生成以下结果。

PHP类访问控制修饰符
PHP if
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

Operator

Introduction

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }